private RelNode endGenOBLogicalPlan(RelNode sortRel) throws CalciteSemanticException {
      ImmutableMap<String, Integer> hiveColNameCalcitePosMap =
              calcitePlannerAction.buildHiveToCalciteColumnMap(outputRR);
      calcitePlannerAction.relToHiveRR.put(sortRel, outputRR);
      calcitePlannerAction.relToHiveColNameCalcitePosMap.put(sortRel, hiveColNameCalcitePosMap);

      RowResolver selectOutputRR = selPair.getValue();
      if (selectOutputRR != null) {
        List<RexNode> originalInputRefs = calcitePlannerAction.toRexNodeList(selPair.getKey());
        List<RexNode> selectedRefs = originalInputRefs.subList(0, selectOutputRR.getColumnInfos().size());
        // We need to add select since order by schema may have more columns than result schema.
        return calcitePlannerAction.genSelectRelNode(selectedRefs, selectOutputRR, sortRel);
      }

      return sortRel;
    }
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