private static List<FieldNode> preserveColumnOrder(Operator<? extends OperatorDesc> op,
      List<FieldNode> cols)
      throws SemanticException {
    RowSchema inputSchema = op.getSchema();
    if (inputSchema != null) {
      List<FieldNode> rs = new ArrayList<>();
      List<ColumnInfo> inputCols = inputSchema.getSignature();
      for (ColumnInfo i: inputCols) {
        FieldNode fn = lookupColumn(cols, i.getInternalName());
        if (fn != null) {
          rs.add(fn);
        }
      }
      return rs;
    } else {
      return cols;
    }
  }
The pruning needs to preserve the order of columns in the input schema
@param op
@param cols
@return
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/optimizer/ColumnPrunerProcFactory.java