private static SortKeyInfo getSortKeyInfo(POLocalRearrange rearrange) throws ExecException {
SortKeyInfo result = new SortKeyInfo();
List<PhysicalPlan> plans = rearrange.getPlans();
nextPlan: for (int i = 0; i < plans.size(); i++) {
PhysicalPlan plan = plans.get(i);
ColumnChainInfo columnChainInfo = new ColumnChainInfo();
if (plan.getRoots() == null) {
log.debug("POLocalRearrange plan is null");
return null;
} else if (plan.getRoots().size() != 1) {
// POLocalRearrange plan contains more than 1 root.
// Probably there is an Expression operator in the local
// rearrangement plan, skip this plan
continue nextPlan;
} else {
List<Integer> columns = new ArrayList<Integer>();
columns
.add(rearrange.getIndex()
& PigNullableWritable.idxSpace);
// The first item inside columnChainInfo is set to type Tuple.
// This value is not actually in use, but it intends to match
// the type of POProject in reduce side
columnChainInfo.insert(columns, DataType.TUPLE);
PhysicalOperator node = plan.getRoots().get(0);
while (node != null) {
if (node instanceof POProject) {
POProject project = (POProject) node;
if(project.isProjectToEnd()){
columnChainInfo.insert(project.getStartCol(),
project.getResultType());
}else {
columnChainInfo.insert(
project.getColumns(), project.getResultType());
}
if (plan.getSuccessors(node) == null)
node = null;