private static void pruneOperator(NodeProcessorCtx ctx,
                                    Operator<? extends OperatorDesc> op,
                                    List<FieldNode> cols)
      throws SemanticException {
    // the pruning needs to preserve the order of columns in the input schema
    RowSchema inputSchema = op.getSchema();
    if (inputSchema != null) {
      ArrayList<ColumnInfo> rs = new ArrayList<ColumnInfo>();
      RowSchema oldRS = op.getSchema();
      for(ColumnInfo i : oldRS.getSignature()) {
        if (lookupColumn(cols, i.getInternalName()) != null) {
          rs.add(i);
        } else {
          Map<String, ExprNodeDesc> columnExprMap = op.getColumnExprMap();
          if (columnExprMap != null) {
            columnExprMap.remove(i.getInternalName());
          }
        }
      }
      op.getSchema().setSignature(rs);
    }
  }
The Node Processor for Column Pruning on Union Operators.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/ColumnPrunerProcFactory.java