return curIndex;
}
private void mergeOneReducePlanWithIndex(PhysicalPlan from,
PhysicalPlan to, int initial, int current, byte mapKeyType) throws VisitorException {
POPackage pk = (POPackage)from.getRoots().get(0);
from.remove(pk);
if(!(pk instanceof POMultiQueryPackage)){
// XXX the index of the original keyInfo map is always 0,
// we need to shift the index so that the lookups works
// with the new indexed key
addShiftedKeyInfoIndex(initial, pk);
}
int total = current - initial;
POMultiQueryPackage pkg = (POMultiQueryPackage)to.getRoots().get(0);
int pkCount = 0;
if (pk instanceof POMultiQueryPackage) {
List<POPackage> pkgs = ((POMultiQueryPackage)pk).getPackages();
for (POPackage p : pkgs) {
pkg.addPackage(p);
pkCount++;
}
addShiftedKeyInfoIndex(initial, current, (POMultiQueryPackage)pk);
} else {
pkg.addPackage(pk);
pkCount = 1;
}
if (pkCount != total) {
int errCode = 2146;
String msg = "Internal Error. Inconsistency in key index found during optimization.";
throw new OptimizerException(msg, errCode, PigException.BUG);
}
boolean[] keyPos = pk.getKeyPositionsInTuple();
PODemux demux = (PODemux)to.getLeaves().get(0);
int plCount = 0;
PhysicalOperator root = from.getRoots().get(0);
if (root instanceof PODemux) {
// flattening the inner plans of the demux operator.
// This is based on the fact that if a plan has a demux
// operator, then it's the only operator in the plan.
List<PhysicalPlan> pls = ((PODemux)root).getPlans();
for (PhysicalPlan pl : pls) {
demux.addPlan(pl, keyPos);
plCount++;
}
demux.addIsKeyWrappedList(((PODemux)root).getIsKeyWrappedList());
} else {
demux.addPlan(from, mapKeyType, keyPos);
plCount = 1;
}
if (plCount != total) {
int errCode = 2146;
String msg = "Internal Error. Inconsistency in key index found during optimization.";
throw new OptimizerException(msg, errCode, PigException.BUG);
}
if (demux.isSameMapKeyType()) {
pkg.setKeyType(pk.getKeyType());
} else {
pkg.setKeyType(DataType.TUPLE);
}
}