public class JoinToMultiJoinRule extends RelOptRule
LogicalJoins
into a single MultiJoin with N inputs.
An input is not flattened if the input is a null generating input in an outer join, i.e., either input in a full outer join, the right hand side of a left outer join, or the left hand side of a right outer join.
Join conditions are also pulled up from the inputs into the topmost
MultiJoin,
unless the input corresponds to a null generating input in an outer join,
Outer join information is also stored in the MultiJoin. A
boolean flag indicates if the join is a full outer join, and in the case of
left and right outer joins, the join type and outer join conditions are
stored in arrays in the MultiJoin. This outer join information is
associated with the null generating input in the outer join. So, in the case
of a a left outer join between A and B, the information is associated with B,
not A.
Here are examples of the MultiJoins constructed after this rule
has been applied on following join trees.
The constructor is parameterized to allow any sub-class of
Join, not just
LogicalJoin.
| Modifier and Type | Class and Description |
|---|---|
private class |
JoinToMultiJoinRule.InputReferenceCounter
Visitor that keeps a reference count of the inputs used by an expression.
|
| Modifier and Type | Field and Description |
|---|---|
static JoinToMultiJoinRule |
INSTANCE |
description, operands, relBuilderFactory| Constructor and Description |
|---|
JoinToMultiJoinRule(Class<? extends Join> clazz)
Deprecated.
|
JoinToMultiJoinRule(Class<? extends Join> clazz,
RelBuilderFactory relBuilderFactory)
Creates a JoinToMultiJoinRule.
|
| Modifier and Type | Method and Description |
|---|---|
private com.google.common.collect.ImmutableMap<Integer,ImmutableIntList> |
addOnJoinFieldRefCounts(List<RelNode> multiJoinInputs,
int nTotalFields,
RexNode joinCondition,
List<int[]> origJoinFieldRefCounts)
Adds on to the existing join condition reference counts the references
from the new join condition.
|
private boolean |
canCombine(RelNode input,
boolean nullGenerating)
Returns whether an input can be merged into a given relational expression
without changing semantics.
|
private List<RelNode> |
combineInputs(Join join,
RelNode left,
RelNode right,
List<ImmutableBitSet> projFieldsList,
List<int[]> joinFieldRefCountsList)
Combines the inputs into a LogicalJoin into an array of inputs.
|
private List<RexNode> |
combineJoinFilters(Join joinRel,
RelNode left,
RelNode right)
Combines the join filters from the left and right inputs (if they are
MultiJoinRels) with the join filter in the joinrel into a single AND'd
join filter, unless the inputs correspond to null generating inputs in an
outer join
|
private void |
combineOuterJoins(Join joinRel,
List<RelNode> combinedInputs,
RelNode left,
RelNode right,
List<Pair<JoinRelType,RexNode>> joinSpecs)
Combines the outer join conditions and join types from the left and right
join inputs.
|
private List<RexNode> |
combinePostJoinFilters(Join joinRel,
RelNode left,
RelNode right)
Combines the post-join filters from the left and right inputs (if they
are MultiJoinRels) into a single AND'd filter.
|
private void |
copyOuterJoinInfo(MultiJoin multiJoin,
List<Pair<JoinRelType,RexNode>> destJoinSpecs,
int adjustmentAmount,
List<RelDataTypeField> srcFields,
List<RelDataTypeField> destFields)
Copies outer join data from a source MultiJoin to a new set of arrays.
|
void |
onMatch(RelOptRuleCall call)
Receives notification about a rule match.
|
private RexNode |
shiftRightFilter(Join joinRel,
RelNode left,
MultiJoin right,
RexNode rightFilter)
Shifts a filter originating from the right child of the LogicalJoin to the
right, to reflect the filter now being applied on the resulting
MultiJoin.
|
any, convert, convert, convertList, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, operand, operand, operand, operand, operand, some, toString, unorderedpublic static final JoinToMultiJoinRule INSTANCE
@Deprecated public JoinToMultiJoinRule(Class<? extends Join> clazz)
public JoinToMultiJoinRule(Class<? extends Join> clazz, RelBuilderFactory relBuilderFactory)
public void onMatch(RelOptRuleCall call)
RelOptRulecall.rels holds the set of relational
expressions which match the operands to the rule;
call.rels[0] is the root expression.
Typically a rule would check that the nodes are valid matches, creates
a new expression, then calls back RelOptRuleCall.transformTo(org.apache.calcite.rel.RelNode, java.util.Map<org.apache.calcite.rel.RelNode, org.apache.calcite.rel.RelNode>) to
register the expression.
onMatch in class RelOptRulecall - Rule callRelOptRule.matches(RelOptRuleCall)private List<RelNode> combineInputs(Join join, RelNode left, RelNode right, List<ImmutableBitSet> projFieldsList, List<int[]> joinFieldRefCountsList)
join - original joinleft - left input into joinright - right input into joinprojFieldsList - returns a list of the new combined projection
fieldsjoinFieldRefCountsList - returns a list of the new combined join
field reference countsprivate void combineOuterJoins(Join joinRel, List<RelNode> combinedInputs, RelNode left, RelNode right, List<Pair<JoinRelType,RexNode>> joinSpecs)
joinRel - join relcombinedInputs - the combined inputs to the joinleft - left child of the joinrelright - right child of the joinreljoinSpecs - the list where the join types and conditions will be
copiedprivate void copyOuterJoinInfo(MultiJoin multiJoin, List<Pair<JoinRelType,RexNode>> destJoinSpecs, int adjustmentAmount, List<RelDataTypeField> srcFields, List<RelDataTypeField> destFields)
multiJoin - the source MultiJoindestJoinSpecs - the list where the join types and conditions will
be copiedadjustmentAmount - if > 0, the amount the RexInputRefs in the join
conditions need to be adjusted bysrcFields - the source fields that the original join conditions
are referencingdestFields - the destination fields that the new join conditionsprivate List<RexNode> combineJoinFilters(Join joinRel, RelNode left, RelNode right)
joinRel - join relleft - left child of the joinright - right child of the joinprivate boolean canCombine(RelNode input, boolean nullGenerating)
input - input into a joinnullGenerating - true if the input is null generatingprivate RexNode shiftRightFilter(Join joinRel, RelNode left, MultiJoin right, RexNode rightFilter)
joinRel - the original LogicalJoinleft - the left child of the LogicalJoinright - the right child of the LogicalJoinrightFilter - the filter originating from the right childprivate com.google.common.collect.ImmutableMap<Integer,ImmutableIntList> addOnJoinFieldRefCounts(List<RelNode> multiJoinInputs, int nTotalFields, RexNode joinCondition, List<int[]> origJoinFieldRefCounts)
multiJoinInputs - inputs into the new MultiJoinnTotalFields - total number of fields in the MultiJoinjoinCondition - the new join conditionorigJoinFieldRefCounts - existing join condition reference countsprivate List<RexNode> combinePostJoinFilters(Join joinRel, RelNode left, RelNode right)
joinRel - the original LogicalJoinleft - left child of the LogicalJoinright - right child of the LogicalJoinCopyright © 2012–2018 The Apache Software Foundation. All rights reserved.