Package org.apache.calcite.sql2rel
Class RelDecorrelator
java.lang.Object
org.apache.calcite.sql2rel.RelDecorrelator
- All Implemented Interfaces:
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Planner rule that adjusts projects when counts are added.static interface
Base configuration for rules that are non-static in a RelDecorrelator.protected static class
static class
Builds aRelDecorrelator.CorelMap
.static final class
Planner rule that removes correlations for scalar aggregates.static final class
Planner rule that removes correlations for scalar projects.static final class
Rule to remove an Aggregate with SINGLE_VALUE. -
Field Summary
Modifier and TypeFieldDescriptionprotected RelDecorrelator.CorelMap
protected final Context
protected @Nullable RelNode
protected final ReflectUtil.MethodDispatcher<@Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame>
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.protected final RelBuilder
-
Constructor Summary
ModifierConstructorDescriptionprotected
RelDecorrelator
(RelDecorrelator.CorelMap cm, Context context, RelBuilder relBuilder) -
Method Summary
Modifier and TypeMethodDescriptionprotected RelNode
decorrelate
(RelNode root) protected RexNode
decorrelateExpr
(RelNode currentRel, Map<RelNode, org.apache.calcite.sql2rel.RelDecorrelator.Frame> map, RelDecorrelator.CorelMap cm, RexNode exp) static RelNode
decorrelateQuery
(RelNode rootRel) Deprecated.static RelNode
decorrelateQuery
(RelNode rootRel, RelBuilder relBuilder) Decorrelates a query.@Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Aggregate rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Correlate rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Filter rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Join rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Project rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Sort rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(Values rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalAggregate rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalCorrelate rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalFilter rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalJoin rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalProject rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalSnapshot rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(LogicalTableFunctionScan rel, boolean isCorVarDefined) @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
decorrelateRel
(RelNode rel, boolean isCorVarDefined) Fallback if none of the otherdecorrelateRel
methods match.@Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame
protected Collection<RelOptRule>
Returns the rules applied on the rel after decorrelation, never null.protected RelDecorrelator
Returns thevisitor
on which theMethodDispatcher
dispatches eachdecorrelateRel
method, the default implementation returns this instance, if you got a sub-class, override this method to replace thevisitor
as the sub-class instance.protected RelBuilderFactory
protected RexNode
removeCorrelationExpr
(RexNode exp, boolean projectPulledAboveLeftCorrelator) protected RexNode
removeCorrelationExpr
(RexNode exp, boolean projectPulledAboveLeftCorrelator, Set<Integer> isCount) protected RexNode
removeCorrelationExpr
(RexNode exp, boolean projectPulledAboveLeftCorrelator, RexInputRef nullIndicator)
-
Field Details
-
relBuilder
-
cm
-
dispatcher
protected final ReflectUtil.MethodDispatcher<@Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame> dispatcher -
currentRel
-
context
-
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
-
-
Constructor Details
-
RelDecorrelator
-
-
Method Details
-
decorrelateQuery
Deprecated. -
decorrelateQuery
Decorrelates a query.This is the main entry point to
RelDecorrelator
.- Parameters:
rootRel
- Root node of the queryrelBuilder
- Builder for relational expressions- Returns:
- Equivalent query with all
Correlate
instances removed
-
relBuilderFactory
-
decorrelate
-
removeCorrelationViaRule
-
decorrelateExpr
-
removeCorrelationExpr
-
removeCorrelationExpr
protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator, RexInputRef nullIndicator) -
removeCorrelationExpr
-
decorrelateRel
public @Nullable org.apache.calcite.sql2rel.RelDecorrelator.Frame decorrelateRel(RelNode rel, boolean isCorVarDefined) Fallback if none of the otherdecorrelateRel
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
-
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
Returns thevisitor
on which theMethodDispatcher
dispatches eachdecorrelateRel
method, the default implementation returns this instance, if you got a sub-class, override this method to replace thevisitor
as the sub-class instance. -
getPostDecorrelateRules
Returns the rules applied on the rel after decorrelation, never null.
-