private RelNode executeProgram(RelNode basePlan, HepProgram program, RelMetadataProvider mdProvider,
        RexExecutor executorProvider, List<? extends RelOptMaterialization> materializations, boolean noDag) {

      final String ruleExclusionRegex = conf.get(ConfVars.HIVE_CBO_RULE_EXCLUSION_REGEX.varname, "");

      // Create planner and copy context
      HepPlanner planner =
          new HepPlanner(program, basePlan.getCluster().getPlanner().getContext(), noDag, null, RelOptCostImpl.FACTORY);
      planner.addListener(new RuleEventLogger());
      List<RelMetadataProvider> list = Lists.newArrayList();
      list.add(mdProvider);
      planner.registerMetadataProviders(list);
      RelMetadataProvider chainedProvider = ChainedRelMetadataProvider.of(list);
      cluster.setMetadataProvider(
          new CachingRelMetadataProvider(chainedProvider, planner));

      if (executorProvider != null) {
        // basePlan.getCluster.getPlanner is the VolcanoPlanner from apply()
        // both planners need to use the correct executor
        cluster.getPlanner().setExecutor(executorProvider);
        planner.setExecutor(executorProvider);
      }

      if (materializations != null) {
        // Add materializations to planner
        for (RelOptMaterialization materialization : materializations) {
          planner.addMaterialization(materialization);
        }
      }

      if (!ruleExclusionRegex.isEmpty()) {
        LOG.info("The CBO rules matching the following regex are excluded from planning: {}",
            ruleExclusionRegex);
        planner.setRuleDescExclusionFilter(Pattern.compile(ruleExclusionRegex));
      }
      planner.setRoot(basePlan);

      return planner.findBestExp();
    }
Generate a HEP program with the given rule set.

@param isCollection
@param order
@param rules
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java