private RelNode applySearchExpandTransforms(RelNode basePlan, RelMetadataProvider mdProvider,
        RexExecutor executor) {
      HepProgramBuilder searchProgram = new HepProgramBuilder();
      searchProgram.addRuleCollection(ImmutableList.of(HiveSearchRules.FILTER_SEARCH_EXPAND,
          HiveSearchRules.PROJECT_SEARCH_EXPAND,
          HiveSearchRules.JOIN_SEARCH_EXPAND));
      return executeProgram(basePlan, searchProgram.build(), mdProvider, executor);
    }
Code responsible for Calcite plan generation and optimization.
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java