assert rel.getRowType().getFieldCount() == oldLeftFieldCount + oldRightFieldCount;
private boolean filterRefersToBothSidesOfJoin(RexNode filter, Join j) { boolean refersToBothSides = false; int joinNoOfProjects = j.getRowType().getFieldCount(); ImmutableBitSet filterProjs = ImmutableBitSet.FROM_BIT_SET.apply(new BitSet(joinNoOfProjects)); ImmutableBitSet allLeftProjs = filterProjs.union(ImmutableBitSet.range(0, j.getInput(0) .getRowType().getFieldCount())); ImmutableBitSet allRightProjs = filterProjs.union(ImmutableBitSet.range(j.getInput(0) .getRowType().getFieldCount(), joinNoOfProjects)); filterProjs = filterProjs.union(InputFinder.bits(filter)); if (allLeftProjs.intersects(filterProjs) && allRightProjs.intersects(filterProjs)) refersToBothSides = true; return refersToBothSides; } }
nullIndicatorPos, typeFactory.createTypeWithNullability( join.getRowType().getFieldList().get(nullIndicatorPos) .getType(), true));
List<RelDataTypeField> joinFields = join.getRowType().getFieldList(); List<RelDataTypeField> swappedJoinFeilds = swappedJoin.getRowType().getFieldList(); for(RexNode project:topProject.getProjects()) { RexNode newProject = project.accept(new RelOptUtil.RexInputConverter(rexBuilder, swappedJoinFeilds,
@Override public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final HepRelVertex root = (HepRelVertex) call.getPlanner().getRoot(); if (root.getCurrentRel() != join) { // Bail out return; } // The join is the root, but we should always end up with a Project operator // on top. We will add it. RelBuilder relBuilder = call.builder(); relBuilder.push(join); List<RexNode> identityFields = relBuilder.fields( ImmutableBitSet.range(0, join.getRowType().getFieldCount()).asList()); relBuilder.project(identityFields, ImmutableList.<String>of(), true); call.transformTo(relBuilder.build()); }
private boolean filterRefersToBothSidesOfJoin(RexNode filter, Join j) { boolean refersToBothSides = false; int joinNoOfProjects = j.getRowType().getFieldCount(); ImmutableBitSet filterProjs = ImmutableBitSet.FROM_BIT_SET.apply(new BitSet(joinNoOfProjects)); ImmutableBitSet allLeftProjs = filterProjs.union(ImmutableBitSet.range(0, j.getInput(0) .getRowType().getFieldCount())); ImmutableBitSet allRightProjs = filterProjs.union(ImmutableBitSet.range(j.getInput(0) .getRowType().getFieldCount(), joinNoOfProjects)); filterProjs = filterProjs.union(InputFinder.bits(filter)); if (allLeftProjs.intersects(filterProjs) && allRightProjs.intersects(filterProjs)) refersToBothSides = true; return refersToBothSides; } }
final ImmutableBitSet rightBits = ImmutableBitSet.range(left.getRowType().getFieldCount(), join.getRowType().getFieldCount()); if (topRefs.intersects(rightBits)) { return; Join rightJoin = (Join)(((HepRelVertex)aggregate.getInput()).getCurrentRel()); List<RexNode> projects = new ArrayList<>(); for(int i=0; i<rightJoin.getRowType().getFieldCount(); i++){ projects.add(rexBuilder.makeInputRef(rightJoin, i)); RelNode topProject = call.builder().push(rightJoin).project(projects, rightJoin.getRowType().getFieldNames(), true).build(); semi = call.builder().push(left).push(topProject).semiJoin(newCondition).build();
int nullIndicatorPos = join.getRowType().getFieldCount() - 1; nullIndicatorPos, cluster.getTypeFactory().createTypeWithNullability( join.getRowType().getFieldList() .get(nullIndicatorPos).getType(), true));
final ImmutableBitSet rightBits = ImmutableBitSet.range(leftInput.getRowType().getFieldCount(), join.getRowType().getFieldCount()); int joinFieldCount = join.getRowType().getFieldCount(); Mapping mappingLR = Mappings.create(MappingType.PARTIAL_FUNCTION, joinFieldCount, joinFieldCount); Mapping mappingRL = Mappings.create(MappingType.PARTIAL_FUNCTION, joinFieldCount, joinFieldCount);
join.getRowType().getFieldCount(), belowOffset); final RexNode newCondition =
final ImmutableBitSet rightBits = ImmutableBitSet.range(left.getRowType().getFieldCount(), join.getRowType().getFieldCount()); if (bits.intersects(rightBits)) { return; Join rightJoin = (Join)(((HepRelVertex)aggregate.getInput()).getCurrentRel()); List<RexNode> projects = new ArrayList<>(); for(int i=0; i<rightJoin.getRowType().getFieldCount(); i++){ projects.add(rexBuilder.makeInputRef(rightJoin, i)); RelNode topProject = call.builder().push(rightJoin).project(projects, rightJoin.getRowType().getFieldNames(), true).build(); semi = call.builder().push(left).push(topProject).semiJoin(newCondition).build();
join.getRowType().getFieldCount(), belowOffset); final RexNode newCondition =
ImmutableBitSet.range( left.getRowType().getFieldCount(), join.getRowType().getFieldCount() );
private List<Double> averageJoinColumnSizes(Join rel, RelMetadataQuery mq, boolean semijoin) { final RelNode left = rel.getLeft(); final RelNode right = rel.getRight(); final List<Double> lefts = mq.getAverageColumnSizes(left); final List<Double> rights = semijoin ? null : mq.getAverageColumnSizes(right); if (lefts == null && rights == null) { return null; } final int fieldCount = rel.getRowType().getFieldCount(); Double[] sizes = new Double[fieldCount]; if (lefts != null) { lefts.toArray(sizes); } if (rights != null) { final int leftCount = left.getRowType().getFieldCount(); for (int i = 0; i < rights.size(); i++) { sizes[leftCount + i] = rights.get(i); } } return ImmutableNullableList.copyOf(sizes); }
private List<Double> averageJoinColumnSizes(Join rel, RelMetadataQuery mq, boolean semijoin) { final RelNode left = rel.getLeft(); final RelNode right = rel.getRight(); final List<Double> lefts = mq.getAverageColumnSizes(left); final List<Double> rights = semijoin ? null : mq.getAverageColumnSizes(right); if (lefts == null && rights == null) { return null; } final int fieldCount = rel.getRowType().getFieldCount(); Double[] sizes = new Double[fieldCount]; if (lefts != null) { lefts.toArray(sizes); } if (rights != null) { final int leftCount = left.getRowType().getFieldCount(); for (int i = 0; i < rights.size(); i++) { sizes[leftCount + i] = rights.get(i); } } return ImmutableNullableList.copyOf(sizes); }
public void run() throws InterruptedException { List<Row> rightList = null; final int leftCount = rel.getLeft().getRowType().getFieldCount(); final int rightCount = rel.getRight().getRowType().getFieldCount(); context.values = new Object[rel.getRowType().getFieldCount()]; Row left; Row right; while ((left = leftSource.receive()) != null) { System.arraycopy(left.getValues(), 0, context.values, 0, leftCount); if (rightList == null) { rightList = new ArrayList<>(); while ((right = rightSource.receive()) != null) { rightList.add(right); } } for (Row right2 : rightList) { System.arraycopy(right2.getValues(), 0, context.values, leftCount, rightCount); final Boolean execute = (Boolean) condition.execute(context); if (execute != null && execute) { sink.send(Row.asCopy(context.values)); } } } } }
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(join.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(join.getCondition()), e); builder.push(join.getLeft()); builder.push(join.getRight()); final int fieldCount = join.getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 2, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.join(join.getJoinType(), shuttle.apply(join.getCondition())); builder.project(fields(builder, join.getRowType().getFieldCount())); call.transformTo(builder.build()); } }
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final RelBuilder builder = call.builder(); final RexSubQuery e = RexUtil.SubQueryFinder.find(join.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(join.getCondition()), e); builder.push(join.getLeft()); builder.push(join.getRight()); final int fieldCount = join.getRowType().getFieldCount(); final RexNode target = apply(e, ImmutableSet.of(), logic, builder, 2, fieldCount); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.join(join.getJoinType(), shuttle.apply(join.getCondition())); builder.project(fields(builder, join.getRowType().getFieldCount())); call.transformTo(builder.build()); } }
private boolean filterRefersToBothSidesOfJoin(RexNode filter, Join j) { boolean refersToBothSides = false; int joinNoOfProjects = j.getRowType().getFieldCount(); ImmutableBitSet filterProjs = ImmutableBitSet.FROM_BIT_SET.apply(new BitSet(joinNoOfProjects)); ImmutableBitSet allLeftProjs = filterProjs.union(ImmutableBitSet.range(0, j.getInput(0) .getRowType().getFieldCount())); ImmutableBitSet allRightProjs = filterProjs.union(ImmutableBitSet.range(j.getInput(0) .getRowType().getFieldCount(), joinNoOfProjects)); filterProjs = filterProjs.union(InputFinder.bits(filter)); if (allLeftProjs.intersects(filterProjs) && allRightProjs.intersects(filterProjs)) refersToBothSides = true; return refersToBothSides; } }
public void onMatch(final RelOptRuleCall call) { Join join = call.rel(0); if (!join.getSystemFieldList().isEmpty()) { // FIXME Enable this rule for joins with system fields return; } final RelNode swapped = swap(join, this.swapOuter, call.builder()); if (swapped == null) { return; } // The result is either a Project or, if the project is trivial, a // raw Join. final Join newJoin = swapped instanceof Join ? (Join) swapped : (Join) swapped.getInput(0); call.transformTo(swapped); // We have converted join='a join b' into swapped='select // a0,a1,a2,b0,b1 from b join a'. Now register that project='select // b0,b1,a0,a1,a2 from (select a0,a1,a2,b0,b1 from b join a)' is the // same as 'b join a'. If we didn't do this, the swap join rule // would fire on the new join, ad infinitum. final RelBuilder relBuilder = call.builder(); final List<RexNode> exps = RelOptUtil.createSwappedJoinExprs(newJoin, join, false); relBuilder.push(swapped) .project(exps, newJoin.getRowType().getFieldNames()); call.getPlanner().ensureRegistered(relBuilder.build(), newJoin); }