List<POLocalRearrangeTez> rearranges = PlanHelper.getPhysicalOperators(from.plan, POLocalRearrangeTez.class);
if (rearranges.isEmpty()) {
return;
}
POLocalRearrangeTez connectingLR = null;
PhysicalPlan rearrangePlan = from.plan;
for (POLocalRearrangeTez lr : rearranges) {
if (lr.getOutputKey().equals(to.getOperatorKey().toString())) {
connectingLR = lr;
break;
}
}
if (connectingLR == null) {
return;
}
// Detected the POLocalRearrange -> POPackage pattern
TezEdgeDescriptor inEdge = to.inEdges.get(from.getOperatorKey());
// Only optimize for Cogroup case
if (from.isGlobalSort()) {
return;
}
// If there is a custom partitioner do not do secondary key optimization.
if (inEdge.partitionerClass != null) {
return;
}
if (from.plan.getOperator(connectingLR.getOperatorKey()) == null) {
// The POLocalRearrange is sub-plan of a POSplit
rearrangePlan = PlanHelper.getLocalRearrangePlanFromSplit(from.plan, connectingLR.getOperatorKey());
}
SecondaryKeyOptimizerInfo info = SecondaryKeyOptimizerUtil.applySecondaryKeySort(rearrangePlan, to.plan);
if (info != null) {
numSortRemoved += info.getNumSortRemoved();