private int getFieldIndexFromColumnNumber(RowResolver selectOutputRR, ASTNode ref) throws SemanticException {
      int fieldIndex;
      int pos = Integer.parseInt(ref.getText());
      if (pos > 0 && pos <= selectOutputRR.getColumnInfos().size()) {
        // fieldIndex becomes so simple
        // Note that pos starts from 1 while fieldIndex starts from 0;
        fieldIndex = pos - 1;
      } else {
        throw new SemanticException(
                ErrorMsg.INVALID_POSITION_ALIAS_IN_ORDERBY.getMsg("Position alias: " + pos
                        + " does not exist\n" + "The Select List is indexed from 1 to "
                        + selectOutputRR.getColumnInfos().size()));
      }
      return fieldIndex;
    }
This method can be called at startup time to pre-register all the
additional Hive classes (compared to Calcite core classes) that may
be visited during the planning phase in the metadata providers
and the field trimmer.
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java