int numMerges = 0;
PhysicalPlan splitterPl = isMapOnly(mr) ? mr.mapPlan : mr.reducePlan;
POStore storeOp = (POStore)splitterPl.getLeaves().get(0);
POSplit splitOp = null;
// case 3: multiple splittees and at least one of them is map-only
if (mappers.size() > 0) {
splitOp = getSplit();
int n = mergeAllMapOnlySplittees(mappers, mr, splitOp);
log.info("Merged " + n + " map-only splittees.");
numMerges += n;
}
// case 4: multiple splittees and at least one of them has reducer
if (isMapOnly(mr) && mapReducers.size() > 0) {
PhysicalOperator leaf = splitterPl.getLeaves().get(0);
splitOp = (leaf instanceof POStore) ? getSplit() : (POSplit)leaf;
int n = mergeMapReduceSplittees(mapReducers, mr, splitOp);
log.info("Merged " + n + " map-reduce splittees.");
numMerges += n;
}
// finally, add original store to the split operator
// if there is splittee that hasn't been merged
if (splitOp != null
&& (numMerges < numSplittees)) {
PhysicalPlan storePlan = new PhysicalPlan();
try {
storePlan.addAsLeaf(storeOp);
splitOp.addPlan(storePlan);
} catch (PlanException e) {
int errCode = 2129;
String msg = "Internal Error. Unable to add store to the split plan for optimization.";
throw new OptimizerException(msg, errCode, PigException.BUG, e);
}