final PhysicalJoinType physicalJoinType,
final RelNode left, final RelNode right,
final RelCollation collationLeft, final RelCollation collationRight) throws InvalidRelException {
DrillDistributionTrait distBroadcastRight = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.BROADCAST_DISTRIBUTED);
RelTraitSet traitsRight = null;
if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
assert collationLeft != null && collationRight != null;
traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(collationRight).plus(distBroadcastRight);
} else {
traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(distBroadcastRight);
}
final RelTraitSet traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL);
final RelNode convertedLeft = convert(left, traitsLeft);
final RelNode convertedRight = convert(right, traitsRight);
new SubsetTransformer<DrillJoinRel, InvalidRelException>(call){
public RelNode convertChild(final DrillJoinRel join, final RelNode rel) throws InvalidRelException {
DrillDistributionTrait toDist = rel.getTraitSet().getTrait(DrillDistributionTraitDef.INSTANCE);
RelTraitSet newTraitsLeft;
if (physicalJoinType == PhysicalJoinType.MERGE_JOIN) {
newTraitsLeft = newTraitSet(Prel.DRILL_PHYSICAL, collationLeft, toDist);
} else {
newTraitsLeft = newTraitSet(Prel.DRILL_PHYSICAL, toDist);
}