private Operator<? extends OperatorDesc> genOutputSelectForGroupBy(
        Operator<? extends OperatorDesc> parentOp, Operator<? extends OperatorDesc> currOp) {
      assert (parentOp.getSchema().getSignature().size() == currOp.getSchema().getSignature().size());
      Iterator<ColumnInfo> pIter = parentOp.getSchema().getSignature().iterator();
      Iterator<ColumnInfo> cIter = currOp.getSchema().getSignature().iterator();
      List<ExprNodeDesc> columns = new ArrayList<ExprNodeDesc>();
      List<String> colName = new ArrayList<String>();
      Map<String, ExprNodeDesc> columnExprMap = new HashMap<String, ExprNodeDesc>();
      while (pIter.hasNext()) {
        ColumnInfo pInfo = pIter.next();
        ColumnInfo cInfo = cIter.next();
        ExprNodeDesc column = new ExprNodeColumnDesc(pInfo.getType(), pInfo.getInternalName(),
            pInfo.getTabAlias(), pInfo.getIsVirtualCol(), pInfo.isSkewedCol());
        columns.add(column);
        colName.add(cInfo.getInternalName());
        columnExprMap.put(cInfo.getInternalName(), column);
      }
      return OperatorFactory.getAndMakeChild(new SelectDesc(columns, colName),
          new RowSchema(currOp.getSchema().getSignature()), columnExprMap, parentOp);
    }
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