private ASTNode getSubQueryGroupByAST() {
    ASTNode groupBy = null;
    if ( subQueryAST.getChild(1).getChildCount() > 3 &&
        subQueryAST.getChild(1).getChild(3).getType() == HiveParser.TOK_GROUPBY ) {
      groupBy = (ASTNode) subQueryAST.getChild(1).getChild(3);
    }

    if ( groupBy != null ) {
      return groupBy;
    }

    groupBy = SubQueryUtils.buildGroupBy();
    groupByAddedToSQ = true;

    List<ASTNode> newChildren = new ArrayList<ASTNode>();
    newChildren.add(groupBy);
    if ( subQueryAST.getChildCount() > 3) {
      for( int i = subQueryAST.getChildCount() - 1; i >= 3; i-- ) {
        ASTNode child = (ASTNode) subQueryAST.getChild(i);
        newChildren.add(child);
      }
    }

    for(ASTNode child : newChildren ) {
      subQueryAST.addChild(child);
    }

    subQueryDiagnostic.setAddGroupByClause();

    return groupBy;
  }
@param parentQueryRR
@param forHavingClause
@param outerQueryAlias
@return true if it is correlated scalar subquery with an aggregate
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/parse/QBSubQuery.java