private static boolean genColNameMap(
      Operator<? extends OperatorDesc> op, List<String> currColNames) {

    List<ExprNodeDesc> colList = null;
    List<String> outputColNames = null;

    assert(op.columnNamesRowResolvedCanBeObtained());
    // Only select operators among the allowed operators can cause changes in the
    // column names
    if (op instanceof SelectOperator) {
      SelectDesc selectDesc = ((SelectOperator)op).getConf();
      if (!selectDesc.isSelStarNoCompute()) {
        colList = selectDesc.getColList();
        outputColNames = selectDesc.getOutputColumnNames();

        // Only columns and constants can be selected
        for (int pos = 0; pos < colList.size(); pos++) {
          ExprNodeDesc colExpr = colList.get(pos);
          String outputColName = outputColNames.get(pos);

          // If it is not a column we need for the keys, move on
          if (!currColNames.contains(outputColName)) {
            continue;
          }

          if (colExpr instanceof ExprNodeConstantDesc) {
            currColNames.remove(outputColName);
            continue;
          } else if (colExpr instanceof ExprNodeColumnDesc) {
            String inputColName = ((ExprNodeColumnDesc) colExpr).getColumn();
            if (!outputColName.equals(inputColName)) {
              currColNames.set(currColNames.indexOf(outputColName), inputColName);
            }
          } else {
            // the column map can not be generated
            return false;
          }
        }
      }
    }

    return true;
  }
This method traces up from the given operator to the root
of the operator graph until a TableScanOperator is reached.
Along the way, if any operators are present that do not
provide a direct mapping from columns of the base table to
the keys on the input operator, the trace-back is stopped at that
point. If the trace back can be done successfully, the method
returns the root TableScanOperator as well as the list of column
names on that table that map to the keys used for the input
operator (which is currently only a join or group by).
ql/src/java/org/apache/hadoop/hive/ql/parse/TableAccessAnalyzer.java