@Override public Double getRowCount(Sort rel, RelMetadataQuery mq) { final Double rowCount = mq.getRowCount(rel.getInput()); if (rowCount != null && rel.fetch != null) { final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); final int limit = RexLiteral.intValue(rel.fetch); final Double offsetLimit = new Double(offset + limit); // offsetLimit is smaller than rowCount of the input operator // thus, we return the offsetLimit if (offsetLimit < rowCount) { return offsetLimit; } } return rowCount; }
@Override public Double getRowCount(Sort rel, RelMetadataQuery mq) { final Double rowCount = mq.getRowCount(rel.getInput()); if (rowCount != null && rel.fetch != null) { final int offset = rel.offset == null ? 0 : RexLiteral.intValue(rel.offset); final int limit = RexLiteral.intValue(rel.fetch); final Double offsetLimit = new Double(offset + limit); // offsetLimit is smaller than rowCount of the input operator // thus, we return the offsetLimit if (offsetLimit < rowCount) { return offsetLimit; } } return rowCount; }
public RelNode align(Sort rel, List<RelFieldCollation> collations) { final RelNode child = dispatchAlign(rel.getInput(), rel.collation.getFieldCollations()); return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
public RelNode align(Sort rel, List<RelFieldCollation> collations) { final RelNode child = dispatchAlign(rel.getInput(), rel.collation.getFieldCollations()); return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
final int count = sort.getInput().getRowType().getFieldCount(); if (count == 1) { final RelOptPredicateList predicates = mq.getPulledUpPredicates(sort.getInput()); if (predicates == null) { return; Map<RexNode, RexNode> constants = new HashMap<>(); for (int i = 0; i < count ; i++) { RexNode expr = rexBuilder.makeInputRef(sort.getInput(), i); if (conditionsExtracted.containsKey(expr)) { constants.put(expr, conditionsExtracted.get(expr)); List<RelDataTypeField> fields = sort.getInput().getRowType().getFieldList(); List<Pair<RexNode, String>> newChildExprs = new ArrayList<>(); List<RexNode> topChildExprs = new ArrayList<>(); List<String> topChildExprsFields = new ArrayList<>(); for (int i = 0; i < count ; i++) { RexNode expr = rexBuilder.makeInputRef(sort.getInput(), i); RelDataTypeField field = fields.get(i); if (constants.containsKey(expr)) { RelOptUtil.permutation(Pair.left(newChildExprs), sort.getInput().getRowType()).inverse(); List<RelFieldCollation> fieldCollations = new ArrayList<>(); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { relBuilder.push(sort.getInput()); relBuilder.project(Pair.left(newChildExprs), Pair.right(newChildExprs)); final ImmutableList<RexNode> sortFields =
final int count = sort.getInput().getRowType().getFieldCount(); if (count == 1) { final RelOptPredicateList predicates = mq.getPulledUpPredicates(sort.getInput()); if (predicates == null) { return; Map<RexNode, RexNode> constants = new HashMap<>(); for (int i = 0; i < count ; i++) { RexNode expr = rexBuilder.makeInputRef(sort.getInput(), i); if (conditionsExtracted.containsKey(expr)) { constants.put(expr, conditionsExtracted.get(expr)); List<RelDataTypeField> fields = sort.getInput().getRowType().getFieldList(); List<Pair<RexNode, String>> newChildExprs = new ArrayList<>(); List<RexNode> topChildExprs = new ArrayList<>(); List<String> topChildExprsFields = new ArrayList<>(); for (int i = 0; i < count ; i++) { RexNode expr = rexBuilder.makeInputRef(sort.getInput(), i); RelDataTypeField field = fields.get(i); if (constants.containsKey(expr)) { RelOptUtil.permutation(Pair.left(newChildExprs), sort.getInput().getRowType()).inverse(); List<RelFieldCollation> fieldCollations = new ArrayList<>(); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { relBuilder.push(sort.getInput()); relBuilder.project(Pair.left(newChildExprs), Pair.right(newChildExprs)); final ImmutableList<RexNode> sortFields =
@Override public RelNode convert(RelNode rel) { final Sort sort = (Sort) rel; if (sort.offset != null || sort.fetch != null) { return null; } final RelTraitSet traitSet = sort.getTraitSet().replace(OLAPRel.CONVENTION); final RelNode input = sort.getInput(); return new OLAPSortRel(rel.getCluster(), traitSet, convert(input, input.getTraitSet().replace(OLAPRel.CONVENTION)), sort.getCollation(), sort.offset, sort.fetch); }
if (sort2.offset == null && sort2.fetch == null) { stack.pop(); push(sort2.getInput()); final RelNode sort = sortFactory.createSort(build(), sort2.collation, if (sort2.offset == null && sort2.fetch == null) { stack.pop(); push(sort2.getInput()); final RelNode sort = sortFactory.createSort(build(), sort2.collation,
first.getInput(), first.getCollation(), offset == 0 ? null : call.builder().literal(offset),
final RelNode oldInput = rel.getInput(); final Frame frame = getInvoke(oldInput, rel); if (frame == null) {
if (sort2.offset == null && sort2.fetch == null) { stack.pop(); push(sort2.getInput()); final RelNode sort = sortFactory.createSort(build(), sort2.collation, if (sort2.offset == null && sort2.fetch == null) { stack.pop(); push(sort2.getInput()); final RelNode sort = sortFactory.createSort(build(), sort2.collation,
@Override public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); if (sort.offset == null && sort.fetch == null) { return; } RelTraitSet origTraitSet = sort.getTraitSet(); RelTraitSet traitSet = origTraitSet.replace(OLAPRel.CONVENTION).simplify(); RelNode input = sort.getInput(); if (!sort.getCollation().getFieldCollations().isEmpty()) { // Create a sort with the same sort key, but no offset or fetch. input = sort.copy(sort.getTraitSet(), input, sort.getCollation(), null, null); } RelNode x = convert(input, input.getTraitSet().replace(OLAPRel.CONVENTION)); call.transformTo(new OLAPLimitRel(sort.getCluster(), traitSet, x, sort.offset, sort.fetch)); }
final RelNode oldInput = rel.getInput(); final Frame frame = getInvoke(oldInput, rel); if (frame == null) {
final MutableRel input = toMutable(sort.getInput()); return MutableSort.of(input, sort.getCollation(), sort.offset, sort.fetch);
/** * Table references from Sort. */ public Set<RelTableRef> getTableReferences(Sort rel, RelMetadataQuery mq) { return mq.getTableReferences(rel.getInput()); }
/** * Extract predicates for a Sort. */ public RelOptPredicateList getAllPredicates(Sort sort, RelMetadataQuery mq) { return mq.getAllPredicates(sort.getInput()); }
/** * Infers predicates for a Sort. */ public RelOptPredicateList getPredicates(Sort sort, RelMetadataQuery mq) { RelNode input = sort.getInput(); return mq.getPulledUpPredicates(input); }
public RelNode convert(RelNode rel) { final Sort sort = (Sort) rel; final RelTraitSet traitSet = sort.getTraitSet().replace(BindableConvention.INSTANCE); final RelNode input = sort.getInput(); return new BindableSort(rel.getCluster(), traitSet, convert(input, input.getTraitSet().replace(BindableConvention.INSTANCE)), sort.getCollation(), sort.offset, sort.fetch); } }
@Override public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); final RelNode input = sort.getInput(); final RelTraitSet traits = sort.getTraitSet().plus(Rel.LOGICAL); final RelNode convertedInput = convert(input, input.getTraitSet().plus(Rel.LOGICAL).simplify()); call.transformTo(new SortRel(sort.getCluster(), traits, convertedInput, sort.getCollation())); } }