Class RelDecorrelator

java.lang.Object
org.apache.calcite.sql2rel.RelDecorrelator
All Implemented Interfaces:
ReflectiveVisitor

public class RelDecorrelator extends Object implements ReflectiveVisitor
RelDecorrelator replaces all correlated expressions (corExp) in a relational expression (RelNode) tree with non-correlated expressions that are produced from joining the RelNode that produces the corExp with the RelNode that references it.

TODO:

  • replace CorelMap constructor parameter with a RelNode
  • make currentRel immutable (would require a fresh RelDecorrelator for each node being decorrelated)
  • make fields of CorelMap immutable
  • make sub-class rules static, and have them create their own de-correlator

Note: make all the members protected scope so that they can be accessed by the sub-class.

  • Field Details

    • relBuilder

      protected final RelBuilder relBuilder
    • cm

    • dispatcher

      protected final ReflectUtil.MethodDispatcher<@Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame> dispatcher
    • currentRel

      protected @Nullable RelNode currentRel
    • context

      protected final Context context
    • map

      protected final Map<RelNode,org.apache.calcite.sql2rel.RelDecorrelator.Frame> map
      Built during decorrelation, of rel to all the newly created correlated variables in its output, and to map old input positions to new input positions. This is from the view point of the parent rel of a new rel.
    • generatedCorRels

      protected final HashSet<Correlate> generatedCorRels
  • Constructor Details

  • Method Details

    • decorrelateQuery

      @Deprecated public static RelNode decorrelateQuery(RelNode rootRel)
      Deprecated.
    • decorrelateQuery

      public static RelNode decorrelateQuery(RelNode rootRel, RelBuilder relBuilder)
      Decorrelates a query.

      This is the main entry point to RelDecorrelator.

      Parameters:
      rootRel - Root node of the query
      relBuilder - Builder for relational expressions
      Returns:
      Equivalent query with all Correlate instances removed
    • relBuilderFactory

      protected RelBuilderFactory relBuilderFactory()
    • decorrelate

      protected RelNode decorrelate(RelNode root)
    • removeCorrelationViaRule

      public RelNode removeCorrelationViaRule(RelNode root)
    • decorrelateExpr

      protected RexNode decorrelateExpr(RelNode currentRel, Map<RelNode,org.apache.calcite.sql2rel.RelDecorrelator.Frame> map, RelDecorrelator.CorelMap cm, RexNode exp)
    • removeCorrelationExpr

      protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator)
    • removeCorrelationExpr

      protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator, RexInputRef nullIndicator)
    • removeCorrelationExpr

      protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator, Set<Integer> isCount)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(RelNode rel, boolean isCorVarDefined)
      Fallback if none of the other decorrelateRel methods match.
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Sort rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Values rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalAggregate rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Aggregate rel, boolean isCorVarDefined)
    • getInvoke

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame getInvoke(RelNode r, boolean isCorVarDefined, @Nullable RelNode parent)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalProject rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Project rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalSnapshot rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalTableFunctionScan rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalFilter rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Filter rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalCorrelate rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Correlate rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(LogicalJoin rel, boolean isCorVarDefined)
    • decorrelateRel

      public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(Join rel, boolean isCorVarDefined)
    • getVisitor

      protected RelDecorrelator getVisitor()
      Returns the visitor on which the MethodDispatcher dispatches each decorrelateRel method, the default implementation returns this instance, if you got a sub-class, override this method to replace the visitor as the sub-class instance.
    • getPostDecorrelateRules

      protected Collection<RelOptRule> getPostDecorrelateRules()
      Returns the rules applied on the rel after decorrelation, never null.