use of org.apache.calcite.rel.rules.MultiJoin in project calcite by apache.
the class RelOptUtil method projectMultiJoin.
/**
* Creates a new {@link org.apache.calcite.rel.rules.MultiJoin} to reflect
* projection references from a
* {@link org.apache.calcite.rel.logical.LogicalProject} that is on top of the
* {@link org.apache.calcite.rel.rules.MultiJoin}.
*
* @param multiJoin the original MultiJoin
* @param project the LogicalProject on top of the MultiJoin
* @return the new MultiJoin
*/
public static MultiJoin projectMultiJoin(MultiJoin multiJoin, LogicalProject project) {
// Locate all input references in the projection expressions as well
// the post-join filter. Since the filter effectively sits in
// between the LogicalProject and the MultiJoin, the projection needs
// to include those filter references.
ImmutableBitSet inputRefs = InputFinder.bits(project.getProjects(), multiJoin.getPostJoinFilter());
// create new copies of the bitmaps
List<RelNode> multiJoinInputs = multiJoin.getInputs();
List<BitSet> newProjFields = Lists.newArrayList();
for (RelNode multiJoinInput : multiJoinInputs) {
newProjFields.add(new BitSet(multiJoinInput.getRowType().getFieldCount()));
}
// set the bits found in the expressions
int currInput = -1;
int startField = 0;
int nFields = 0;
for (int bit : inputRefs) {
while (bit >= (startField + nFields)) {
startField += nFields;
currInput++;
assert currInput < multiJoinInputs.size();
nFields = multiJoinInputs.get(currInput).getRowType().getFieldCount();
}
newProjFields.get(currInput).set(bit - startField);
}
// for each input
return new MultiJoin(multiJoin.getCluster(), multiJoin.getInputs(), multiJoin.getJoinFilter(), multiJoin.getRowType(), multiJoin.isFullOuterJoin(), multiJoin.getOuterJoinConditions(), multiJoin.getJoinTypes(), Lists.transform(newProjFields, ImmutableBitSet.FROM_BIT_SET), multiJoin.getJoinFieldRefCountsMap(), multiJoin.getPostJoinFilter());
}
Aggregations