public class RelDecorrelator extends Object implements ReflectiveVisitor
TODO:
CorelMap constructor parameter with a RelNode
currentRel immutable (would require a fresh
RelDecorrelator for each node being decorrelated)CorelMap immutable| Modifier and Type | Class and Description |
|---|---|
private class |
RelDecorrelator.AdjustProjectForCountAggregateRule
Planner rule that adjusts projects when counts are added.
|
(package private) static class |
RelDecorrelator.CorDef
A correlation and a field.
|
private static class |
RelDecorrelator.CorelMap
A map of the locations of
LogicalCorrelate
in a tree of RelNodes. |
private static class |
RelDecorrelator.CorelMapBuilder
Builds a
RelDecorrelator.CorelMap. |
(package private) static class |
RelDecorrelator.CorRef
A unique reference to a correlation field.
|
private static class |
RelDecorrelator.DecorrelateRexShuttle
Shuttle that decorrelates.
|
(package private) static class |
RelDecorrelator.Frame
Frame describing the relational expression after decorrelation
and where to find the output fields and correlation variables
among its output fields.
|
private class |
RelDecorrelator.RemoveCorrelationForScalarAggregateRule
Planner rule that removes correlations for scalar aggregates.
|
private class |
RelDecorrelator.RemoveCorrelationForScalarProjectRule
Planner rule that removes correlations for scalar projects.
|
private class |
RelDecorrelator.RemoveCorrelationRexShuttle
Shuttle that removes correlations.
|
private class |
RelDecorrelator.RemoveSingleAggregateRule
Rule to remove single_value rel.
|
| Modifier and Type | Field and Description |
|---|---|
private RelDecorrelator.CorelMap |
cm |
private Context |
context |
private RelNode |
currentRel |
private ReflectUtil.MethodDispatcher<RelDecorrelator.Frame> |
dispatcher |
private HashSet<LogicalCorrelate> |
generatedCorRels |
private Map<RelNode,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.
|
private RelBuilder |
relBuilder |
private RexBuilder |
rexBuilder |
private static org.slf4j.Logger |
SQL2REL_LOGGER |
| Modifier | Constructor and Description |
|---|---|
private |
RelDecorrelator(RelOptCluster cluster,
RelDecorrelator.CorelMap cm,
Context context) |
| Modifier and Type | Method and Description |
|---|---|
private RelNode |
aggregateCorrelatorOutput(Correlate correlate,
LogicalProject project,
Set<Integer> isCount)
|
(package private) static boolean |
allLessThan(Collection<Integer> integers,
int limit,
Litmus ret) |
private boolean |
checkCorVars(LogicalCorrelate correlate,
LogicalProject project,
LogicalFilter filter,
List<RexFieldAccess> correlatedJoinKeys)
Checks whether the correlations in projRel and filter are related to
the correlated variables provided by corRel.
|
private Function2<RelNode,RelNode,Void> |
createCopyHook() |
private HepPlanner |
createPlanner(HepProgram program) |
private RelNode |
createProjectWithAdditionalExprs(RelNode input,
List<Pair<RexNode,String>> additionalExprs)
Projects all
input output fields plus the additional expressions. |
private RelNode |
createValueGenerator(Iterable<RelDecorrelator.CorRef> correlations,
int valueGenFieldOffset,
SortedMap<RelDecorrelator.CorDef,Integer> corDefOutputs)
Create RelNode tree that produces a list of correlated variables.
|
private RelNode |
decorrelate(RelNode root) |
protected RexNode |
decorrelateExpr(RelNode currentRel,
Map<RelNode,RelDecorrelator.Frame> map,
RelDecorrelator.CorelMap cm,
RexNode exp) |
private RelDecorrelator.Frame |
decorrelateInputWithValueGenerator(RelNode rel,
RelDecorrelator.Frame frame) |
static RelNode |
decorrelateQuery(RelNode rootRel)
Decorrelates a query.
|
RelDecorrelator.Frame |
decorrelateRel(LogicalAggregate rel)
Rewrites a
LogicalAggregate. |
RelDecorrelator.Frame |
decorrelateRel(LogicalCorrelate rel)
Rewrite Correlate into a left outer join.
|
RelDecorrelator.Frame |
decorrelateRel(LogicalFilter rel)
Rewrite LogicalFilter.
|
RelDecorrelator.Frame |
decorrelateRel(LogicalJoin rel)
Rewrite LogicalJoin.
|
RelDecorrelator.Frame |
decorrelateRel(LogicalProject rel)
Rewrite LogicalProject.
|
RelDecorrelator.Frame |
decorrelateRel(RelNode rel)
Fallback if none of the other
decorrelateRel methods match. |
RelDecorrelator.Frame |
decorrelateRel(Sort rel)
Rewrite Sort.
|
RelDecorrelator.Frame |
decorrelateRel(Values rel)
Rewrites a
Values. |
private void |
findCorrelationEquivalent(RelDecorrelator.CorRef correlation,
RexNode e)
Finds a
RexInputRef that is equivalent to a RelDecorrelator.CorRef,
and if found, throws a Util.FoundOne. |
private RelNode |
getCorRel(RelDecorrelator.CorRef corVar) |
private RelDecorrelator.Frame |
getFrame(RelNode r,
boolean safe) |
RelDecorrelator.Frame |
getInvoke(RelNode r,
RelNode parent) |
private static RexInputRef |
getNewForOldInputRef(RelNode currentRel,
Map<RelNode,RelDecorrelator.Frame> map,
RexInputRef oldInputRef) |
private boolean |
has(Collection<RelDecorrelator.CorDef> corDefs,
RelDecorrelator.CorRef corr)
Returns whether a
CorrelationId is satisfied by at least one of a
collection of RelDecorrelator.CorDefs. |
private boolean |
hasAll(Collection<RelDecorrelator.CorRef> corRefs,
Collection<RelDecorrelator.CorDef> corDefs)
Returns whether all of a collection of
RelDecorrelator.CorRefs are satisfied
by at least one of a collection of RelDecorrelator.CorDefs. |
(package private) static Map<Integer,Integer> |
identityMap(int count) |
private boolean |
isWidening(RelDataType type,
RelDataType type1)
Returns whether one type is just a widening of another.
|
private RelDecorrelator.Frame |
maybeAddValueGenerator(RelNode rel,
RelDecorrelator.Frame frame)
Adds a value generator to satisfy the correlating variables used by
a relational expression, if those variables are not already provided by
its input.
|
private static RexLiteral |
projectedLiteral(RelNode rel,
int i)
Returns a literal output field, or null if it is not literal.
|
private RelNode |
projectJoinOutputWithNullability(LogicalJoin join,
LogicalProject project,
int nullIndicatorPos)
Pulls project above the join from its RHS input.
|
private boolean |
references(RexNode e,
RelDecorrelator.CorRef correlation) |
(package private) RelDecorrelator.Frame |
register(RelNode rel,
RelNode newRel,
Map<Integer,Integer> oldToNewOutputs,
SortedMap<RelDecorrelator.CorDef,Integer> corDefOutputs)
Registers a relational expression and the relational expression it became
after decorrelation.
|
protected RexNode |
removeCorrelationExpr(RexNode exp,
boolean projectPulledAboveLeftCorrelator) |
protected RexNode |
removeCorrelationExpr(RexNode exp,
boolean projectPulledAboveLeftCorrelator,
RexInputRef nullIndicator) |
protected RexNode |
removeCorrelationExpr(RexNode exp,
boolean projectPulledAboveLeftCorrelator,
Set<Integer> isCount) |
RelNode |
removeCorrelationViaRule(RelNode root) |
private void |
removeCorVarFromTree(LogicalCorrelate correlate)
Remove correlated variables from the tree at root corRel
|
private void |
setCurrent(RelNode root,
LogicalCorrelate corRel) |
private static RelNode |
stripHep(RelNode rel) |
private static final org.slf4j.Logger SQL2REL_LOGGER
private final RelBuilder relBuilder
private RelDecorrelator.CorelMap cm
private final ReflectUtil.MethodDispatcher<RelDecorrelator.Frame> dispatcher
private final RexBuilder rexBuilder
private RelNode currentRel
private final Context context
private final Map<RelNode,RelDecorrelator.Frame> map
private final HashSet<LogicalCorrelate> generatedCorRels
private RelDecorrelator(RelOptCluster cluster, RelDecorrelator.CorelMap cm, Context context)
public static RelNode decorrelateQuery(RelNode rootRel)
This is the main entry point to RelDecorrelator.
rootRel - Root node of the queryLogicalCorrelate instances removedprivate void setCurrent(RelNode root, LogicalCorrelate corRel)
private HepPlanner createPlanner(HepProgram program)
protected RexNode decorrelateExpr(RelNode currentRel, Map<RelNode,RelDecorrelator.Frame> map, RelDecorrelator.CorelMap cm, RexNode exp)
protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator)
protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator, RexInputRef nullIndicator)
protected RexNode removeCorrelationExpr(RexNode exp, boolean projectPulledAboveLeftCorrelator, Set<Integer> isCount)
public RelDecorrelator.Frame decorrelateRel(RelNode rel)
decorrelateRel methods match.public RelDecorrelator.Frame decorrelateRel(Sort rel)
rel - Sort to be rewrittenpublic RelDecorrelator.Frame decorrelateRel(Values rel)
Values.rel - Values to be rewrittenpublic RelDecorrelator.Frame decorrelateRel(LogicalAggregate rel)
LogicalAggregate.rel - Aggregate to rewritepublic RelDecorrelator.Frame getInvoke(RelNode r, RelNode parent)
private static RexLiteral projectedLiteral(RelNode rel, int i)
public RelDecorrelator.Frame decorrelateRel(LogicalProject rel)
rel - the project rel to rewriteprivate RelNode createValueGenerator(Iterable<RelDecorrelator.CorRef> correlations, int valueGenFieldOffset, SortedMap<RelDecorrelator.CorDef,Integer> corDefOutputs)
correlations - correlated variables to generatevalueGenFieldOffset - offset in the output that generated columns
will startcorDefOutputs - output positions for the correlated variables
generatedprivate RelDecorrelator.Frame getFrame(RelNode r, boolean safe)
private RelNode getCorRel(RelDecorrelator.CorRef corVar)
private RelDecorrelator.Frame maybeAddValueGenerator(RelNode rel, RelDecorrelator.Frame frame)
private boolean hasAll(Collection<RelDecorrelator.CorRef> corRefs, Collection<RelDecorrelator.CorDef> corDefs)
RelDecorrelator.CorRefs are satisfied
by at least one of a collection of RelDecorrelator.CorDefs.private boolean has(Collection<RelDecorrelator.CorDef> corDefs, RelDecorrelator.CorRef corr)
CorrelationId is satisfied by at least one of a
collection of RelDecorrelator.CorDefs.private RelDecorrelator.Frame decorrelateInputWithValueGenerator(RelNode rel, RelDecorrelator.Frame frame)
private void findCorrelationEquivalent(RelDecorrelator.CorRef correlation, RexNode e) throws Util.FoundOne
RexInputRef that is equivalent to a RelDecorrelator.CorRef,
and if found, throws a Util.FoundOne.Util.FoundOneprivate boolean references(RexNode e, RelDecorrelator.CorRef correlation)
private boolean isWidening(RelDataType type, RelDataType type1)
For example:
VARCHAR(10) is a widening of VARCHAR(5).
VARCHAR(10) is a widening of VARCHAR(10) NOT NULL.
public RelDecorrelator.Frame decorrelateRel(LogicalFilter rel)
rel - the filter rel to rewritepublic RelDecorrelator.Frame decorrelateRel(LogicalCorrelate rel)
rel - Correlatorpublic RelDecorrelator.Frame decorrelateRel(LogicalJoin rel)
rel - Joinprivate static RexInputRef getNewForOldInputRef(RelNode currentRel, Map<RelNode,RelDecorrelator.Frame> map, RexInputRef oldInputRef)
private RelNode projectJoinOutputWithNullability(LogicalJoin join, LogicalProject project, int nullIndicatorPos)
join - Joinproject - Original project as the right-hand input of the joinnullIndicatorPos - Position of null indicatorprivate RelNode aggregateCorrelatorOutput(Correlate correlate, LogicalProject project, Set<Integer> isCount)
correlate - Correlateproject - the original project as the RHS input of the joinisCount - Positions which are calls to the COUNT
aggregation functionprivate boolean checkCorVars(LogicalCorrelate correlate, LogicalProject project, LogicalFilter filter, List<RexFieldAccess> correlatedJoinKeys)
correlate - Correlateproject - The original Project as the RHS input of the joinfilter - FiltercorrelatedJoinKeys - Correlated join keysprivate void removeCorVarFromTree(LogicalCorrelate correlate)
correlate - Correlateprivate RelNode createProjectWithAdditionalExprs(RelNode input, List<Pair<RexNode,String>> additionalExprs)
input output fields plus the additional expressions.input - Input relational expressionadditionalExprs - Additional expressions and namesRelDecorrelator.Frame register(RelNode rel, RelNode newRel, Map<Integer,Integer> oldToNewOutputs, SortedMap<RelDecorrelator.CorDef,Integer> corDefOutputs)
static boolean allLessThan(Collection<Integer> integers, int limit, Litmus ret)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.