public static HiveSortExchange create(RelNode input,
      RelDistribution distribution, RelCollation collation) {
    RelOptCluster cluster = input.getCluster();
    distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution);
    collation = RelCollationTraitDef.INSTANCE.canonize(collation);
    RelTraitSet traitSet = getTraitSet(cluster, collation, distribution);
    RelCollation canonizedCollation = traitSet.canonize(RelCollationImpl.of(collation.getFieldCollations()));

    ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
    for (RelFieldCollation relFieldCollation : canonizedCollation.getFieldCollations()) {
      int index = relFieldCollation.getFieldIndex();
      builder.add(cluster.getRexBuilder().makeInputRef(input, index));
    }

    return new HiveSortExchange(cluster, traitSet, input, distribution, collation, builder.build());
  }
Creates a HiveSortExchange.

@param input     Input relational expression
@param distribution Distribution specification
@param collation Collation specification
@param keys Keys specification
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/reloperators/HiveSortExchange.java