private T processGByExpr(Node nd, Object procCtx) throws SemanticException {
    // We recursively create the exprNodeDesc. Base cases: when we encounter
    // a column ref, we convert that into an exprNodeColumnDesc; when we
    // encounter
    // a constant, we convert that into an exprNodeConstantDesc. For others we
    // just
    // build the exprNodeFuncDesc with recursively built children.
    ASTNode expr = (ASTNode) nd;
    TypeCheckCtx ctx = (TypeCheckCtx) procCtx;

    // bypass only if outerRR is not null. Otherwise we need to look for expressions in outerRR for
    // subqueries e.g. select min(b.value) from table b group by b.key
    //                                  having key in (select .. where a = min(b.value)
    if (!ctx.isUseCaching() && ctx.getOuterRR() == null) {
      return null;
    }

    RowResolver input = ctx.getInputRR();
    T desc = null;

    if ((ctx == null) || (input == null) || (!ctx.getAllowGBExprElimination())) {
      return null;
    }

    // If the current subExpression is pre-calculated, as in Group-By etc.
    ColumnInfo colInfo = input.getExpression(expr);
    RowResolver usedRR = input;
    int offset = 0;

    // try outer row resolver
    RowResolver outerRR = ctx.getOuterRR();
    if (colInfo == null && outerRR != null) {
      colInfo = outerRR.getExpression(expr);
      usedRR = outerRR;
      offset = input.getColumnInfos().size();
    }
    if (colInfo != null) {
      desc = exprFactory.createColumnRefExpr(colInfo, usedRR, offset);
      ASTNode source = input.getExpressionSource(expr);
      if (source != null && ctx.getUnparseTranslator() != null) {
        ctx.getUnparseTranslator().addCopyTranslation(expr, source);
      }
      return desc;
    }
    return desc;
  }
Function to do groupby subexpression elimination. This is called by all the
processors initially. As an example, consider the query select a+b,
count(1) from T group by a+b; Then a+b is already precomputed in the group
by operators key, so we substitute a+b in the select list with the internal
column name of the a+b expression that appears in the in input row
resolver.

@param nd      The node that is being inspected.
@param procCtx The processor context.
@return exprNodeColumnDesc.
ql/src/java/org/apache/hadoop/hive/ql/parse/type/TypeCheckProcFactory.java