super(RelOptHelper.any(DrillSortRel.class, DrillRel.DRILL_LOGICAL), "Prel.SortPrule");
}
@Override
public void onMatch(RelOptRuleCall call) {
final DrillSortRel sort = (DrillSortRel) call.rel(0);
final RelNode input = sort.getChild();
// Keep the collation in logical sort. Convert input into a RelNode with 1) this collation, 2) Physical, 3) hash distributed on
DrillDistributionTrait hashDistribution =
new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(getDistributionField(sort)));
final RelTraitSet traits = sort.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(hashDistribution);
final RelNode convertedInput = convert(input, traits);
if(isSingleMode(call)){
call.transformTo(convertedInput);
}else{
RelNode exch = new SingleMergeExchangePrel(sort.getCluster(), sort.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(DrillDistributionTrait.SINGLETON), convertedInput, sort.getCollation());
call.transformTo(exch); // transform logical "sort" into "SingleMergeExchange".
}
}