private void endGroupIfNecessary(int currentChildIndex) throws HiveException {
    if (lastChildIndex != currentChildIndex) {
      for (int i = lastChildIndex; i < currentChildIndex; i++) {
        Operator<? extends OperatorDesc> child = childOperatorsArray[i];
        child.flush();
        child.endGroup();
        for (int childTag: newChildOperatorsTag[i]) {
          child.processGroup(childTag);
        }
      }
      lastChildIndex = currentChildIndex;
    }
  }
We assume that the input rows associated with the same key are ordered by
the tag. Because a tag maps to a childindex, when we see a new childIndex,
we will not see the last childIndex (lastChildIndex) again before we start
a new key group. So, we can call flush the buffer of children
from lastChildIndex (inclusive) to currentChildIndex (exclusive) and
propagate processGroup to those children.
@param currentChildIndex the childIndex we have right now.
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/exec/DemuxOperator.java