Refine search
@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 int count = sort.getInput().getRowType().getFieldCount(); if (count == 1) { final RexBuilder rexBuilder = sort.getCluster().getRexBuilder(); final RelMetadataQuery mq = call.getMetadataQuery(); 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()) { final int target = mapping.getTargetOpt(fc.getFieldIndex()); if (target < 0) {
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { return super.computeSelfCost(planner, mq).multiplyBy(.05); }
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)); }
@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); }
final List<OrderByColumnSpec> orderBys = new ArrayList<>(sort.getChildExps().size()); for (int sortKey = 0; sortKey < sort.getChildExps().size(); sortKey++) { final RexNode sortExpression = sort.getChildExps().get(sortKey); final RelFieldCollation collation = sort.getCollation().getFieldCollations().get(sortKey); final OrderByColumnSpec.Direction direction; final StringComparator comparator;
final RelNode oldInput = rel.getInput(); final Frame frame = getInvoke(oldInput, rel); if (frame == null) { Mappings.target( frame.oldToNewOutputs, oldInput.getRowType().getFieldCount(), newInput.getRowType().getFieldCount()); RelCollation oldCollation = rel.getCollation(); RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
final RelOptCluster cluster = project.getCluster(); if (sort.getConvention() != project.getConvention()) { return; project.getProjects(), project.getInput().getRowType()); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { if (map.getTargetOpt(fc.getFieldIndex()) < 0) { return; RexUtil.apply(map, sort.getCollation())); final Sort newSort = sort.copy( sort.getTraitSet().replace(newCollation), project.getInput(), newCollation, RelNode newProject = project.copy( sort.getTraitSet(), ImmutableList.of(newSort));
public void rewriteRel(Sort rel) { RelCollation oldCollation = rel.getCollation(); final RelNode oldChild = rel.getInput(); final RelNode newChild = getNewForOldRel(oldChild); final Mappings.TargetMapping mapping = getNewForOldInputMapping(oldChild); // validate for (RelFieldCollation field : oldCollation.getFieldCollations()) { int oldInput = field.getFieldIndex(); RelDataType sortFieldType = oldChild.getRowType().getFieldList().get(oldInput).getType(); if (sortFieldType.isStruct()) { // TODO jvs 10-Feb-2005 throw Util.needToImplement("sorting on structured types"); } } RelCollation newCollation = RexUtil.apply(mapping, oldCollation); Sort newRel = LogicalSort.create(newChild, newCollation, rel.offset, rel.fetch); setNewForOldRel(rel, newRel); }
public static boolean orderRelNode(RelNode rel) { if ((rel instanceof Sort) && !((Sort) rel).getCollation().getFieldCollations().isEmpty()) { return true; } return false; }
sort.getCollation(), sort.offset, sort.fetch)) { return; newLeftInput = sort.copy(sort.getTraitSet(), join.getLeft(), sort.getCollation(), sort.offset, sort.fetch); newRightInput = join.getRight(); final RelCollation rightCollation = RelCollationTraitDef.INSTANCE.canonize( RelCollations.shift(sort.getCollation(), -join.getLeft().getRowType().getFieldCount())); newRightInput = sort.copy(sort.getTraitSet().replace(rightCollation), join.getRight(), rightCollation, sort.offset, sort.fetch); final RelNode sortCopy = sort.copy(sort.getTraitSet(), joinCopy, sort.getCollation(), sort.offset, sort.fetch);
public Result visitSort(Sort e) { final Result x = visitChild(0, e.getInput()); final Builder builder = x.builder(e, Clause.ORDER_BY); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation fieldCollation : e.getCollation().getFieldCollations()) { if (fieldCollation.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED && dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.MYSQL) { orderByList.add( ISNULL_FUNCTION.createCall(POS, builder.context.field(fieldCollation.getFieldIndex()))); fieldCollation = new RelFieldCollation(fieldCollation.getFieldIndex(), fieldCollation.getDirection()); } orderByList.add(builder.context.toSql(fieldCollation)); } builder.setOrderBy(new SqlNodeList(orderByList, POS)); return builder.result(); }
public RelNode convert(RelNode rel) { final Sort sort = (Sort) rel; if (sort.offset != null || sort.fetch != null) { return null; } final RelNode input = sort.getInput(); return EnumerableSort.create( convert( input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)), sort.getCollation(), null, null); } }
ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { final RelDataType rowType = sort.getRowType(); final int fieldCount = rowType.getFieldCount(); final RelCollation collation = sort.getCollation(); final RelNode input = sort.getInput(); for (RelFieldCollation field : collation.getFieldCollations()) { inputFieldsUsed.set(field.getFieldIndex());
Iterable<? extends RexNode> nodes) { final List<RelFieldCollation> fieldCollations = new ArrayList<>(); final RelDataType inputRowType = peek().getRowType(); final List<RexNode> extraNodes = projects(inputRowType); final List<RexNode> originalExtraNodes = ImmutableList.copyOf(extraNodes); 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,
if (sort.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sort.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() >= join.getLeft().getRowType().getFieldCount()) { return false; if (sort.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sort.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() < join.getLeft().getRowType().getFieldCount()) { return false;
for (RelNode input : union.getInputs()) { if (!RelMdUtil.checkInputForCollationAndLimit(mq, input, sort.getCollation(), sort.offset, sort.fetch)) { ret = false; Sort branchSort = sort.copy(sort.getTraitSet(), input, sort.getCollation(), sort.offset, sort.fetch); inputs.add(branchSort); } else { Sort result = sort.copy(sort.getTraitSet(), unionCopy, sort.getCollation(), sort.offset, sort.fetch); call.transformTo(result);
@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; }
} else { Sort hiveSortRel = (Sort) node; if (hiveSortRel.getCollation().getFieldCollations().isEmpty()) ASTConverter.this.limit = hiveSortRel; else node.childrenAccept(this);
public RelNode accept(RexShuttle shuttle) { RexNode offset = shuttle.apply(this.offset); RexNode fetch = shuttle.apply(this.fetch); List<RexNode> fieldExps = shuttle.apply(this.fieldExps); assert fieldExps == this.fieldExps : "Sort node does not support modification of input field expressions." + " Old expressions: " + this.fieldExps + ", new ones: " + fieldExps; if (offset == this.offset && fetch == this.fetch) { return this; } return copy(traitSet, getInput(), collation, offset, fetch); }