private void genOBProject() throws SemanticException {
      // selPair.getKey() is the operator right before OB
      // selPair.getValue() is RR which only contains columns needed in result
      // set. Extra columns needed by order by will be absent from it.
      RelNode srcRel = selPair.getKey();
      RowResolver inputRR = calcitePlannerAction.relToHiveRR.get(srcRel);

      // 3. Add Child Project Rel if needed, Generate Output RR, input Sel Rel
      // for top constraining Sel
      obInputRel = srcRel;
      if (!newVCLst.isEmpty()) {
        List<RexNode> originalInputRefs = calcitePlannerAction.toRexNodeList(srcRel);
        RowResolver obSyntheticProjectRR = new RowResolver();
        if (!RowResolver.add(obSyntheticProjectRR, inputRR)) {
          throw new CalciteSemanticException(
                  ERROR_MESSAGE_DUPLICATES_DETECTED,
                  UnsupportedFeature.Duplicates_in_RR);
        }
        int vcolPos = inputRR.getRowSchema().getSignature().size();
        for (Pair<ASTNode, TypeInfo> astTypePair : vcASTTypePairs) {
          obSyntheticProjectRR.putExpression(astTypePair.getKey(), new ColumnInfo(
                  SemanticAnalyzer.getColumnInternalName(vcolPos), astTypePair.getValue(), null,
                  false));
          vcolPos++;
        }
        obInputRel = calcitePlannerAction.genSelectRelNode(CompositeList.of(originalInputRefs, newVCLst),
                obSyntheticProjectRR, srcRel);

        if (outermostOB) {
          if (!RowResolver.add(outputRR, inputRR)) {
            throw new CalciteSemanticException(
                    ERROR_MESSAGE_DUPLICATES_DETECTED,
                    UnsupportedFeature.Duplicates_in_RR);
          }

        } else {
          if (!RowResolver.add(outputRR, obSyntheticProjectRR)) {
            throw new CalciteSemanticException(
                    ERROR_MESSAGE_DUPLICATES_DETECTED,
                    UnsupportedFeature.Duplicates_in_RR);
          }
        }
      } else {
        if (!RowResolver.add(outputRR, inputRR)) {
          throw new CalciteSemanticException(
                  ERROR_MESSAGE_DUPLICATES_DETECTED,
                  UnsupportedFeature.Duplicates_in_RR);
        }
      }
    }
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