@Override
public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx,
Object... nodeOutputs) throws SemanticException {
BucketingSortingCtx bctx = (BucketingSortingCtx)procCtx;
JoinOperator jop = (JoinOperator)nd;
List<ColumnInfo> colInfos = jop.getSchema().getSignature();
Byte[] order = jop.getConf().getTagOrder();
BucketCol[] newBucketCols = null;
SortCol[] newSortCols = null;
for (int i = 0; i < jop.getParentOperators().size(); i++) {
Operator<? extends OperatorDesc> parent = jop.getParentOperators().get(i);
// The caller of this method should guarantee this
assert(parent instanceof ReduceSinkOperator);
ReduceSinkOperator rop = (ReduceSinkOperator)jop.getParentOperators().get(i);
String sortOrder = rop.getConf().getOrder();
List<BucketCol> bucketCols = new ArrayList<BucketCol>();
List<SortCol> sortCols = new ArrayList<SortCol>();
// Go through the Reduce keys and find the matching column(s) in the reduce values
for (int keyIndex = 0; keyIndex < rop.getConf().getKeyCols().size(); keyIndex++) {
for (int valueIndex = 0; valueIndex < rop.getConf().getValueCols().size();
valueIndex++) {
if (new ExprNodeDescEqualityWrapper(rop.getConf().getValueCols().get(valueIndex)).
equals(new ExprNodeDescEqualityWrapper(rop.getConf().getKeyCols().get(
keyIndex)))) {
String colName = rop.getSchema().getSignature().get(valueIndex).getInternalName();
bucketCols.add(new BucketCol(colName, keyIndex));
sortCols.add(new SortCol(colName, keyIndex, sortOrder.charAt(keyIndex)));
break;
}
}
}
if (bucketCols.isEmpty()) {
assert(sortCols.isEmpty());
continue;
}
if (newBucketCols == null) {
assert(newSortCols == null);
// The number of join keys is equal to the number of keys in every reducer, although
// not every key may map to a value in the reducer
newBucketCols = new BucketCol[rop.getConf().getKeyCols().size()];
newSortCols = new SortCol[rop.getConf().getKeyCols().size()];
} else {
assert(newSortCols != null);
}
byte tag = (byte)rop.getConf().getTag();
List<ExprNodeDesc> exprs = jop.getConf().getExprs().get(tag);
int colInfosOffset = 0;
int orderValue = order[tag];
// Columns are output from the join from the different reduce sinks in the order of their
// offsets
for (byte orderIndex = 0; orderIndex < order.length; orderIndex++) {
if (order[orderIndex] < orderValue) {
colInfosOffset += jop.getConf().getExprs().get(orderIndex).size();
}
}
findBucketingSortingColumns(exprs, colInfos, bucketCols, sortCols, newBucketCols,
newSortCols, colInfosOffset);