public static void translateSargToTableColIndexes(
      SearchArgument sarg, Configuration conf, int rootColumn) {
    String nameStr = OrcInputFormat.getNeededColumnNamesString(conf),
        idStr = OrcInputFormat.getSargColumnIDsString(conf);
    String[] knownNames = nameStr.split(",");
    String[] idStrs = (idStr == null) ? null : idStr.split(",");
    assert idStrs == null || knownNames.length == idStrs.length;
    HashMap<String, Integer> nameIdMap = new HashMap<>();
    for (int i = 0; i < knownNames.length; ++i) {
      Integer newId = (idStrs != null) ? Integer.parseInt(idStrs[i]) : i;
      Integer oldId = nameIdMap.put(knownNames[i], newId);
      if (oldId != null && oldId.intValue() != newId.intValue()) {
        throw new RuntimeException("Multiple IDs for " + knownNames[i] + " in column strings: ["
            + idStr + "], [" + nameStr + "]");
      }
    }
    List<PredicateLeaf> leaves = sarg.getLeaves();
    for (int i = 0; i < leaves.size(); ++i) {
      PredicateLeaf pl = leaves.get(i);
      Integer colId = nameIdMap.get(pl.getColumnName());
      String newColName = RecordReaderImpl.encodeTranslatedSargColumn(rootColumn, colId);
      SearchArgumentFactory.setPredicateLeafColumn(pl, newColName);
    }
    LOG.debug("SARG translated into {}", sarg);
  }
Modifies the SARG, replacing column names with column indexes in target table schema. This
basically does the same thing as all the shennannigans with included columns, except for the
last step where ORC gets direct subtypes of root column and uses the ordered match to map
table columns to file columns. The numbers put into predicate leaf should allow to go into
said subtypes directly by index to get the proper index in the file.
This won't work with schema evolution, although it's probably much easier to reason about
if schema evolution was to be supported, because this is a clear boundary between table
schema columns and all things ORC. None of the ORC stuff is used here and none of the
table schema stuff is used after that - ORC doesn't need a bunch of extra crap to apply
the SARG thus modified.
ql/src/java/org/apache/hadoop/hive/ql/io/orc/ExternalCache.java