@Override public boolean matches(final RelOptRuleCall call) { // LIMIT, no ORDER BY final Sort sort = call.rel(0); return sort.collation.getFieldCollations().isEmpty() && sort.fetch != null; }
public static boolean orderRelNode(RelNode rel) { if ((rel instanceof Sort) && !((Sort) rel).getCollation().getFieldCollations().isEmpty()) { return true; } return false; }
public static boolean orderRelNode(RelNode rel) { if ((rel instanceof Sort) && !((Sort) rel).getCollation().getFieldCollations().isEmpty()) { return true; } return false; }
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)); }
/** Returns references to fields for a given collation. */ public ImmutableList<RexNode> fields(RelCollation collation) { final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder(); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { RexNode node = field(fieldCollation.getFieldIndex()); switch (fieldCollation.direction) { case DESCENDING: node = desc(node); } switch (fieldCollation.nullDirection) { case FIRST: node = nullsFirst(node); break; case LAST: node = nullsLast(node); break; } nodes.add(node); } return nodes.build(); }
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 RelFieldCollation collation = sort.getCollation().getFieldCollations().get(sortKey); final OrderByColumnSpec.Direction direction; final StringComparator comparator;
project.getProjects(), project.getInput().getRowType()).inverse(); Set<Integer> needed = new HashSet<>(); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { needed.add(fc.getFieldIndex()); final RexNode node = project.getProjects().get(map.getTarget(fc.getFieldIndex())); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { fieldCollations.add(new RelFieldCollation(m.get(fc.getFieldIndex()), fc.direction, fc.nullDirection));
StringBuilder order = new StringBuilder(); StringBuilder nullOrder = new StringBuilder(); for (RelFieldCollation sortInfo : sortRel.getCollation().getFieldCollations()) { int sortColumnPos = sortInfo.getFieldIndex(); ColumnInfo columnInfo = new ColumnInfo(inputOp.getSchema().getSignature()
final Sort second = call.rel(0); if (second.collation.getFieldCollations().isEmpty()) {
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 void implementRewrite(RewriteImplementor implementor) { implementor.visitChild(this, getInput()); // No need to rewrite "order by" applied on non-olap context. // Occurs in sub-query like "select ... from (...) inner join (...) order by ..." if (this.context.realization == null) return; for (RelFieldCollation fieldCollation : this.collation.getFieldCollations()) { int index = fieldCollation.getFieldIndex(); SQLDigest.OrderEnum order = getOrderEnum(fieldCollation.getDirection()); OLAPRel olapChild = (OLAPRel) this.getInput(); TblColRef orderCol = olapChild.getColumnRowType().getAllColumns().get(index); this.context.addSort(orderCol, order); this.context.storageContext.markSort(); } this.rowType = this.deriveRowType(); this.columnRowType = buildColumnRowType(); }
/** Returns references to fields for a given collation. */ public ImmutableList<RexNode> fields(RelCollation collation) { final ImmutableList.Builder<RexNode> nodes = ImmutableList.builder(); for (RelFieldCollation fieldCollation : collation.getFieldCollations()) { RexNode node = field(fieldCollation.getFieldIndex()); switch (fieldCollation.direction) { case DESCENDING: node = desc(node); } switch (fieldCollation.nullDirection) { case FIRST: node = nullsFirst(node); break; case LAST: node = nullsLast(node); break; } nodes.add(node); } return nodes.build(); }
@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)); }
private void convertOrderLimitToASTNode(HiveSortLimit order) { if (order != null) { HiveSortLimit hiveSortLimit = order; if (!hiveSortLimit.getCollation().getFieldCollations().isEmpty()) { RexNode obExpr; ASTNode astCol; for (RelFieldCollation c : hiveSortLimit.getCollation().getFieldCollations()) {
private void convertOrderLimitToASTNode(HiveSortLimit order) { if (order != null) { HiveSortLimit hiveSortLimit = order; if (!hiveSortLimit.getCollation().getFieldCollations().isEmpty()) { RexNode obExpr; ASTNode astCol; for (RelFieldCollation c : hiveSortLimit.getCollation().getFieldCollations()) {
if (sortLimit.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sortLimit.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() >= join.getLeft().getRowType().getFieldCount()) { if (sortLimit.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sortLimit.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() < join.getLeft().getRowType().getFieldCount()) {
if (sortLimit.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sortLimit.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() >= join.getLeft().getRowType().getFieldCount()) { if (sortLimit.getCollation() != RelCollations.EMPTY) { for (RelFieldCollation relFieldCollation : sortLimit.getCollation().getFieldCollations()) { if (relFieldCollation.getFieldIndex() < join.getLeft().getRowType().getFieldCount()) {
public void onMatch(RelOptRuleCall call) { final HiveSortLimit sort = call.rel(0); final HiveProject project = call.rel(1); // Determine mapping between project input and output fields. If sort // relies on non-trivial expressions, we can't push. final Mappings.TargetMapping map = RelOptUtil.permutation( project.getProjects(), project.getInput().getRowType()); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { if (map.getTargetOpt(fc.getFieldIndex()) < 0) { return; } } // Create new collation final RelCollation newCollation = RelCollationTraitDef.INSTANCE.canonize( RexUtil.apply(map, sort.getCollation())); // New operators final HiveSortLimit newSort = sort.copy(sort.getTraitSet().replace(newCollation), project.getInput(), newCollation, sort.offset, sort.fetch); final RelNode newProject = project.copy(sort.getTraitSet(), ImmutableList.<RelNode>of(newSort)); call.transformTo(newProject); }
public void onMatch(RelOptRuleCall call) { final HiveProject project = call.rel(0); final HiveSortLimit sort = call.rel(1); // Determine mapping between project input and output fields. If sort // relies on non-trivial expressions, we can't push. final Mappings.TargetMapping map = RelOptUtil.permutation( project.getProjects(), project.getInput().getRowType()).inverse(); for (RelFieldCollation fc : sort.getCollation().getFieldCollations()) { if (map.getTarget(fc.getFieldIndex()) < 0) { return; } } // Create new collation final RelCollation newCollation = RelCollationTraitDef.INSTANCE.canonize( RexUtil.apply(map, sort.getCollation())); // New operators final RelNode newProject = project.copy(sort.getInput().getTraitSet(), ImmutableList.<RelNode>of(sort.getInput())); final HiveSortLimit newSort = sort.copy(newProject.getTraitSet(), newProject, newCollation, sort.offset, sort.fetch); call.transformTo(newSort); }