public ImmutableBitSet getSortedInputs() throws CalciteSemanticException { ImmutableBitSet.Builder sortedInputsBuilder = ImmutableBitSet.builder(); JoinPredicateInfo joinPredInfo = HiveCalciteUtil.JoinPredicateInfo. constructJoinPredicateInfo(this); List<ImmutableIntList> joinKeysInChildren = new ArrayList<ImmutableIntList>(); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromLeftPartOfJoinKeysInChildSchema())); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromRightPartOfJoinKeysInChildSchema())); final RelMetadataQuery mq = this.left.getCluster().getMetadataQuery(); for (int i=0; i<this.getInputs().size(); i++) { boolean correctOrderFound = RelCollations.contains( mq.collations(this.getInputs().get(i)), joinKeysInChildren.get(i)); if (correctOrderFound) { sortedInputsBuilder.set(i); } } return sortedInputsBuilder.build(); }
public ImmutableBitSet getSortedInputs() throws CalciteSemanticException { ImmutableBitSet.Builder sortedInputsBuilder = ImmutableBitSet.builder(); JoinPredicateInfo joinPredInfo = HiveCalciteUtil.JoinPredicateInfo. constructJoinPredicateInfo(this); List<ImmutableIntList> joinKeysInChildren = new ArrayList<ImmutableIntList>(); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromLeftPartOfJoinKeysInChildSchema())); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromRightPartOfJoinKeysInChildSchema())); for (int i=0; i<this.getInputs().size(); i++) { boolean correctOrderFound = RelCollations.contains( RelMetadataQuery.instance().collations(this.getInputs().get(i)), joinKeysInChildren.get(i)); if (correctOrderFound) { sortedInputsBuilder.set(i); } } return sortedInputsBuilder.build(); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Filter}'s collation. */ public static List<RelCollation> filter(RelMetadataQuery mq, RelNode input) { return mq.collations(input); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Window}'s collation. * * <p>A Window projects the fields of its input first, followed by the output * from each of its windows. Assuming (quite reasonably) that the * implementation does not re-order its input rows, then any collations of its * input are preserved. */ public static List<RelCollation> window(RelMetadataQuery mq, RelNode input, ImmutableList<Window.Group> groups) { return mq.collations(input); }
/** Helper method to determine a * limit's collation. */ public static List<RelCollation> limit(RelMetadataQuery mq, RelNode input) { return mq.collations(input); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Filter}'s collation. */ public static List<RelCollation> filter(RelMetadataQuery mq, RelNode input) { return mq.collations(input); }
/** Helper method to determine a * limit's collation. */ public static List<RelCollation> limit(RelMetadataQuery mq, RelNode input) { return mq.collations(input); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Window}'s collation. * * <p>A Window projects the fields of its input first, followed by the output * from each of its windows. Assuming (quite reasonably) that the * implementation does not re-order its input rows, then any collations of its * input are preserved. */ public static List<RelCollation> window(RelMetadataQuery mq, RelNode input, ImmutableList<Window.Group> groups) { return mq.collations(input); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Calc}'s collation. */ public static List<RelCollation> calc(RelMetadataQuery mq, RelNode input, RexProgram program) { return program.getCollations(mq.collations(input)); }
/** Helper method to determine a * {@link org.apache.calcite.rel.core.Calc}'s collation. */ public static List<RelCollation> calc(RelMetadataQuery mq, RelNode input, RexProgram program) { return program.getCollations(mq.collations(input)); }
public ImmutableList<RelCollation> collations(HepRelVertex rel, RelMetadataQuery mq) { return mq.collations(rel.getCurrentRel()); }
public ImmutableList<RelCollation> collations(Filter rel, RelMetadataQuery mq) { return mq.collations(rel.getInput()); }
public ImmutableList<RelCollation> collations(Filter rel, RelMetadataQuery mq) { return mq.collations(rel.getInput()); }
public ImmutableList<RelCollation> collations(HepRelVertex rel, RelMetadataQuery mq) { return mq.collations(rel.getCurrentRel()); }
/** Helper method to determine a {@link Join}'s collation assuming that it * uses a merge-join algorithm. * * <p>If the inputs are sorted on other keys <em>in addition to</em> the join * key, the result preserves those collations too. */ public static List<RelCollation> mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys) { final ImmutableList.Builder<RelCollation> builder = ImmutableList.builder(); final ImmutableList<RelCollation> leftCollations = mq.collations(left); assert RelCollations.contains(leftCollations, leftKeys) : "cannot merge join: left input is not sorted on left keys"; builder.addAll(leftCollations); final ImmutableList<RelCollation> rightCollations = mq.collations(right); assert RelCollations.contains(rightCollations, rightKeys) : "cannot merge join: right input is not sorted on right keys"; final int leftFieldCount = left.getRowType().getFieldCount(); for (RelCollation collation : rightCollations) { builder.add(RelCollations.shift(collation, leftFieldCount)); } return builder.build(); } }
/** Helper method to determine a {@link Join}'s collation assuming that it * uses a merge-join algorithm. * * <p>If the inputs are sorted on other keys <em>in addition to</em> the join * key, the result preserves those collations too. */ public static List<RelCollation> mergeJoin(RelMetadataQuery mq, RelNode left, RelNode right, ImmutableIntList leftKeys, ImmutableIntList rightKeys) { final ImmutableList.Builder<RelCollation> builder = ImmutableList.builder(); final ImmutableList<RelCollation> leftCollations = mq.collations(left); assert RelCollations.contains(leftCollations, leftKeys) : "cannot merge join: left input is not sorted on left keys"; builder.addAll(leftCollations); final ImmutableList<RelCollation> rightCollations = mq.collations(right); assert RelCollations.contains(rightCollations, rightKeys) : "cannot merge join: right input is not sorted on right keys"; final int leftFieldCount = left.getRowType().getFieldCount(); for (RelCollation collation : rightCollations) { builder.add(RelCollations.shift(collation, leftFieldCount)); } return builder.build(); } }
public ImmutableBitSet getSortedInputs() { ImmutableBitSet.Builder sortedInputsBuilder = new ImmutableBitSet.Builder(); JoinPredicateInfo joinPredInfo = HiveCalciteUtil.JoinPredicateInfo. constructJoinPredicateInfo(this); List<ImmutableIntList> joinKeysInChildren = new ArrayList<ImmutableIntList>(); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromLeftPartOfJoinKeysInChildSchema())); joinKeysInChildren.add( ImmutableIntList.copyOf( joinPredInfo.getProjsFromRightPartOfJoinKeysInChildSchema())); for (int i=0; i<this.getInputs().size(); i++) { boolean correctOrderFound = RelCollations.contains( RelMetadataQuery.collations(this.getInputs().get(i)), joinKeysInChildren.get(i)); if (correctOrderFound) { sortedInputsBuilder.set(i); } } return sortedInputsBuilder.build(); }
protected TrimResult trimChild( RelNode rel, RelNode input, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { Util.discard(rel); if (input.getClass().getName().endsWith("MedMdrClassExtentRel")) { // MedMdrJoinRule cannot handle Join of Project of // MedMdrClassExtentRel, only naked MedMdrClassExtentRel. // So, disable trimming. fieldsUsed = ImmutableBitSet.range(input.getRowType().getFieldCount()); } final ImmutableList<RelCollation> collations = RelMetadataQuery.collations(input); for (RelCollation collation : collations) { for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { fieldsUsed = fieldsUsed.set(fieldCollation.getFieldIndex()); } } return dispatchTrimFields(input, fieldsUsed, extraFields); }
/** Returns whether a relational expression is already sorted and has fewer * rows than the sum of offset and limit. * * <p>If this is the case, it is safe to push down a * {@link org.apache.calcite.rel.core.Sort} with limit and optional offset. */ public static boolean checkInputForCollationAndLimit(RelMetadataQuery mq, RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { // Check if the input is already sorted boolean alreadySorted = collation.getFieldCollations().isEmpty(); for (RelCollation inputCollation : mq.collations(input)) { if (inputCollation.satisfies(collation)) { alreadySorted = true; break; } } // Check if we are not reducing the number of tuples boolean alreadySmaller = true; final Double rowCount = mq.getMaxRowCount(input); if (rowCount != null && fetch != null) { final int offsetVal = offset == null ? 0 : RexLiteral.intValue(offset); final int limit = RexLiteral.intValue(fetch); if ((double) offsetVal + (double) limit < rowCount) { alreadySmaller = false; } } return alreadySorted && alreadySmaller; } }
/** Returns whether a relational expression is already sorted and has fewer * rows than the sum of offset and limit. * * <p>If this is the case, it is safe to push down a * {@link org.apache.calcite.rel.core.Sort} with limit and optional offset. */ public static boolean checkInputForCollationAndLimit(RelMetadataQuery mq, RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { // Check if the input is already sorted boolean alreadySorted = collation.getFieldCollations().isEmpty(); for (RelCollation inputCollation : mq.collations(input)) { if (inputCollation.satisfies(collation)) { alreadySorted = true; break; } } // Check if we are not reducing the number of tuples boolean alreadySmaller = true; final Double rowCount = mq.getMaxRowCount(input); if (rowCount != null && fetch != null) { final int offsetVal = offset == null ? 0 : RexLiteral.intValue(offset); final int limit = RexLiteral.intValue(fetch); if ((double) offsetVal + (double) limit < rowCount) { alreadySmaller = false; } } return alreadySorted && alreadySmaller; } }