private int getFollowingWorkIndex(TezWork tezWork, UnionWork unionWork, ReduceSinkOperator rs)
      throws SemanticException {
    int index = 0;
    for (BaseWork baseWork : tezWork.getChildren(unionWork)) {
      TezEdgeProperty edgeProperty = tezWork.getEdgeProperty(unionWork, baseWork);
      if (edgeProperty.getEdgeType() != TezEdgeProperty.EdgeType.CONTAINS) {
        return index;
      }
      index++;
    }
    throw new SemanticException("Following work not found for the reduce sink: " + rs.getName());
  }
GenTezWork separates the operator tree into tez tasks.
It is called once per leaf operator (operator that forces
a new execution unit.) and break the operators into work
and tasks along the way.
ql/src/java/org/apache/hadoop/hive/ql/parse/GenTezWork.java