public ImmutableList<RelCollation> collations(HiveAggregate aggregate, RelMetadataQuery mq) { // Compute collations ImmutableList.Builder<RelFieldCollation> collationListBuilder = new ImmutableList.Builder<RelFieldCollation>(); for (int pos : aggregate.getGroupSet().asList()) { final RelFieldCollation fieldCollation = new RelFieldCollation(pos); collationListBuilder.add(fieldCollation); } // Return aggregate collations return ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); }
case LEFT_RELATION: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(leftCollationListBuilder.build()))); break; case RIGHT_RELATION: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(rightCollationListBuilder.build()))); break; default: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); break;
@Override public List<RelCollation> getCollationList() { ImmutableList.Builder<RelFieldCollation> collationList = new ImmutableList.Builder<RelFieldCollation>(); for (Order sortColumn : this.hiveTblMetadata.getSortCols()) { for (int i=0; i<this.hiveTblMetadata.getSd().getCols().size(); i++) { FieldSchema field = this.hiveTblMetadata.getSd().getCols().get(i); if (field.getName().equals(sortColumn.getCol())) { Direction direction; NullDirection nullDirection; if (sortColumn.getOrder() == BaseSemanticAnalyzer.HIVE_COLUMN_ORDER_ASC) { direction = Direction.ASCENDING; nullDirection = NullDirection.FIRST; } else { direction = Direction.DESCENDING; nullDirection = NullDirection.LAST; } collationList.add(new RelFieldCollation(i, direction, nullDirection)); break; } } } return new ImmutableList.Builder<RelCollation>() .add(RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationList.build()))) .build(); }
/** * Creates a HiveSortLimit. * * @param input Input relational expression * @param collation array of sort specifications * @param offset Expression for number of rows to discard before returning * first row * @param fetch Expression for number of rows to fetch */ public static HiveSortLimit create(RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { RelOptCluster cluster = input.getCluster(); collation = RelCollationTraitDef.INSTANCE.canonize(collation); RelTraitSet traitSet = TraitsUtil.getSortTraitSet(cluster, input.getTraitSet(), collation); return new HiveSortLimit(cluster, traitSet, input, collation, offset, fetch); }
/** * Creates a HiveSortLimit. * * @param input Input relational expression * @param collation array of sort specifications * @param offset Expression for number of rows to discard before returning * first row * @param fetch Expression for number of rows to fetch */ public static HiveSortLimit create(RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { RelOptCluster cluster = input.getCluster(); collation = RelCollationTraitDef.INSTANCE.canonize(collation); RelTraitSet traitSet = TraitsUtil.getSortTraitSet(cluster, input.getTraitSet(), collation); return new HiveSortLimit(cluster, traitSet, input, collation, offset, fetch); }
/** * Creates a HiveSortExchange. * * @param input Input relational expression * @param distribution Distribution specification * @param collation Collation specification * @param joinKeys Join Keys specification */ public static HiveSortExchange create(RelNode input, RelDistribution distribution, RelCollation collation, ImmutableList<RexNode> joinKeys) { RelOptCluster cluster = input.getCluster(); distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution); collation = RelCollationTraitDef.INSTANCE.canonize(collation); RelTraitSet traitSet = RelTraitSet.createEmpty().plus(distribution).plus(collation); return new HiveSortExchange(cluster, traitSet, input, distribution, collation, joinKeys); }
/** * Creates a HiveSortExchange. * * @param input Input relational expression * @param distribution Distribution specification * @param collation Collation specification * @param joinKeys Join Keys specification */ public static HiveSortExchange create(RelNode input, RelDistribution distribution, RelCollation collation, ImmutableList<RexNode> joinKeys) { RelOptCluster cluster = input.getCluster(); distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution); collation = RelCollationTraitDef.INSTANCE.canonize(collation); RelTraitSet traitSet = RelTraitSet.createEmpty().plus(distribution).plus(collation); return new HiveSortExchange(cluster, traitSet, input, distribution, collation, joinKeys); }
public ImmutableList<RelCollation> collations(HiveAggregate aggregate, RelMetadataQuery mq) { // Compute collations ImmutableList.Builder<RelFieldCollation> collationListBuilder = new ImmutableList.Builder<RelFieldCollation>(); for (int pos : aggregate.getGroupSet().asList()) { final RelFieldCollation fieldCollation = new RelFieldCollation(pos); collationListBuilder.add(fieldCollation); } // Return aggregate collations return ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); }
case LEFT_RELATION: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(leftCollationListBuilder.build()))); break; case RIGHT_RELATION: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(rightCollationListBuilder.build()))); break; default: collation = ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); break;
@Override public List<RelCollation> getCollationList() { ImmutableList.Builder<RelFieldCollation> collationList = new ImmutableList.Builder<RelFieldCollation>(); for (Order sortColumn : this.hiveTblMetadata.getSortCols()) { for (int i=0; i<this.hiveTblMetadata.getSd().getCols().size(); i++) { FieldSchema field = this.hiveTblMetadata.getSd().getCols().get(i); if (field.getName().equals(sortColumn.getCol())) { Direction direction; NullDirection nullDirection; if (sortColumn.getOrder() == BaseSemanticAnalyzer.HIVE_COLUMN_ORDER_ASC) { direction = Direction.ASCENDING; nullDirection = NullDirection.FIRST; } else { direction = Direction.DESCENDING; nullDirection = NullDirection.LAST; } collationList.add(new RelFieldCollation(i,direction,nullDirection)); break; } } } return new ImmutableList.Builder<RelCollation>() .add(RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationList.build()))) .build(); }
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); }
@Override public void onMatch(RelOptRuleCall call) { final HiveSortLimit sortLimit = call.rel(0); final HiveJoin join = call.rel(1); RelNode inputLeft = join.getLeft(); RelNode inputRight = join.getRight(); // We create a new sort operator on the corresponding input if (join.getJoinType() == JoinRelType.LEFT) { inputLeft = sortLimit.copy(sortLimit.getTraitSet(), inputLeft, sortLimit.getCollation(), sortLimit.offset, sortLimit.fetch); ((HiveSortLimit) inputLeft).setRuleCreated(true); } else { // Adjust right collation final RelCollation rightCollation = RelCollationTraitDef.INSTANCE.canonize( RelCollations.shift(sortLimit.getCollation(), -join.getLeft().getRowType().getFieldCount())); inputRight = sortLimit.copy(sortLimit.getTraitSet().replace(rightCollation), inputRight, rightCollation, sortLimit.offset, sortLimit.fetch); ((HiveSortLimit) inputRight).setRuleCreated(true); } // We copy the join and the top sort operator RelNode result = join.copy(join.getTraitSet(), join.getCondition(), inputLeft, inputRight, join.getJoinType(), join.isSemiJoinDone()); result = sortLimit.copy(sortLimit.getTraitSet(), result, sortLimit.getCollation(), sortLimit.offset, sortLimit.fetch); call.transformTo(result); }
@Override public void onMatch(RelOptRuleCall call) { final HiveSortLimit sortLimit = call.rel(0); final HiveJoin join = call.rel(1); RelNode inputLeft = join.getLeft(); RelNode inputRight = join.getRight(); // We create a new sort operator on the corresponding input if (join.getJoinType() == JoinRelType.LEFT) { inputLeft = sortLimit.copy(sortLimit.getTraitSet(), inputLeft, sortLimit.getCollation(), sortLimit.offset, sortLimit.fetch); ((HiveSortLimit) inputLeft).setRuleCreated(true); } else { // Adjust right collation final RelCollation rightCollation = RelCollationTraitDef.INSTANCE.canonize( RelCollations.shift(sortLimit.getCollation(), -join.getLeft().getRowType().getFieldCount())); inputRight = sortLimit.copy(sortLimit.getTraitSet().replace(rightCollation), inputRight, rightCollation, sortLimit.offset, sortLimit.fetch); ((HiveSortLimit) inputRight).setRuleCreated(true); } // We copy the join and the top sort operator RelNode result = join.copy(join.getTraitSet(), join.getCondition(), inputLeft, inputRight, join.getJoinType(), join.isSemiJoinDone()); result = sortLimit.copy(sortLimit.getTraitSet(), result, sortLimit.getCollation(), sortLimit.offset, sortLimit.fetch); call.transformTo(result); }
public static SampleCrel create(RelNode input) { final RelCollation collation = RelCollationTraitDef.INSTANCE.canonize(RelCollations.EMPTY); final RelTraitSet newTraitSet = input.getTraitSet().replace(Convention.NONE).replace(collation); return new SampleCrel(input.getCluster(), newTraitSet, input); }
/** * Creates a Sort by parsing serialized output. */ public Sort(RelInput input) { this(input.getCluster(), input.getTraitSet().plus(input.getCollation()), input.getInput(), RelCollationTraitDef.INSTANCE.canonize(input.getCollation()), input.getExpression("offset"), input.getExpression("fetch")); }
/** * Creates a Sort by parsing serialized output. */ public Sort(RelInput input) { this(input.getCluster(), input.getTraitSet().plus(input.getCollation()), input.getInput(), RelCollationTraitDef.INSTANCE.canonize(input.getCollation()), input.getExpression("offset"), input.getExpression("fetch")); }
public ImmutableList<RelCollation> collations(HiveAggregate aggregate) { // Compute collations ImmutableList.Builder<RelFieldCollation> collationListBuilder = new ImmutableList.Builder<RelFieldCollation>(); for (int pos : aggregate.getGroupSet().asList()) { final RelFieldCollation fieldCollation = new RelFieldCollation(pos); collationListBuilder.add(fieldCollation); } // Return aggregate collations return ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); }
/** * Creates a SortExchange by parsing serialized output. */ public SortExchange(RelInput input) { this(input.getCluster(), input.getTraitSet().plus(input.getCollation()) .plus(input.getDistribution()), input.getInput(), RelDistributionTraitDef.INSTANCE.canonize(input.getDistribution()), RelCollationTraitDef.INSTANCE.canonize(input.getCollation())); }
/** * Creates a SortExchange by parsing serialized output. */ public SortExchange(RelInput input) { this(input.getCluster(), input.getTraitSet().plus(input.getCollation()) .plus(input.getDistribution()), input.getInput(), RelDistributionTraitDef.INSTANCE.canonize(input.getDistribution()), RelCollationTraitDef.INSTANCE.canonize(input.getCollation())); }