Interface PostOptimizationPlanVerificationAware

All Known Implementing Classes:
OrderBy

public interface PostOptimizationPlanVerificationAware
Interface implemented by expressions that require validation post logical optimization, when the plan and references have been not just resolved but also replaced. The interface is similar to PostOptimizationVerificationAware, but focused on individual expressions or plans, typically covering semantic checks. Generally, whenever one needs to check the plan structure leading to a certain node, which is the node of interest, this node's class needs to implement this interface. Otherwise it may implement PostOptimizationVerificationAware, as more convenient.
  • Method Details

    • postOptimizationPlanVerification

      BiConsumer<LogicalPlan,Failures> postOptimizationPlanVerification()
      Validates the implementing expression - discovered failures are reported to the given Failures class.

      Example: the SORT command, OrderBy, can only be executed currently if it can be associated with a LIMIT Limit and together transformed into a TopN (which is executable). The replacement of the LIMIT+SORT into a TopN is done at the end of the optimization phase. This means that any SORT still existing in the plan post optimization is an error. However, there can be a LIMIT in the plan, but separated from the SORT by an INLINE STATS; in this case, the LIMIT cannot be pushed down near the SORT. To inform the user how they need to modify the query so it can be run, we implement this:

           
      
            @Override
            public BiConsumer<LogicalPlan, Failures> postOptimizationPlanVerification() {
                return (p, failures) -> {
                    if (p instanceof InlineJoin inlineJoin) {
                        inlineJoin.forEachUp(OrderBy.class, orderBy -> {
                            failures.add(
                                fail(
                                    inlineJoin,
                                    "unbounded SORT [{}] not supported before INLINE STATS [{}], move the sort after the INLINE STATS",
                                    orderBy.sourceText(),
                                    inlineJoin.sourceText()
                                )
                            );
                        });
                    } else if (p instanceof OrderBy) {
                        failures.add(fail(p, "Unbounded SORT not supported yet [{}] please add a LIMIT", p.sourceText()));
                    }
                };
            }
           
           

      If we didn't need to check the structure of the plan, it would have sufficed to implement the PostOptimizationVerificationAware interface, which would simply check if there is an instance of OrderBy in the plan.

      Returns:
      a consumer that will receive a tree to check and an accumulator of failures found during inspection.