public boolean removeChildren(Operator<? extends OperatorDesc> currOp, int depth) {
      Operator<? extends OperatorDesc> inputOp = currOp;
      for (int i = 0; i < depth; i++) {
        // If there are more than 1 children at any level, don't do anything
        if ((currOp.getChildOperators() == null) || (currOp.getChildOperators().isEmpty())
            || (currOp.getChildOperators().size() > 1)) {
          return false;
        }
        currOp = currOp.getChildOperators().get(0);
      }

      // add selectOp to match the schema
      // after that, inputOp is the parent of selOp.
      for (Operator<? extends OperatorDesc> op : inputOp.getChildOperators()) {
        op.getParentOperators().clear();
      }
      inputOp.getChildOperators().clear();
      Operator<? extends OperatorDesc> selOp = genOutputSelectForGroupBy(inputOp, currOp);

      // update the childOp of selectOp
      selOp.setChildOperators(currOp.getChildOperators());

      // update the parentOp
      for (Operator<? extends OperatorDesc> op : currOp.getChildOperators()) {
        op.replaceParent(currOp, selOp);
      }
      return true;
    }
Given the group by keys, bucket columns and sort columns, this method
determines if we can use sorted group by or not.

@param groupByCols
@param bucketCols
@param sortCols
@return
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/optimizer/GroupByOptimizer.java