final RelOptPlanner planner = rootRel.getCluster().getPlanner();
planner.setRoot(rootRel);
final RelTraitSet desiredTraits = getDesiredRootTraitSet(rootRel);
final Program program1 =
new Program() {
public RelNode run(RelOptPlanner planner, RelNode rel,
RelTraitSet requiredOutputTraits) {
final DataContext dataContext = context.getDataContext();
planner.setExecutor(new RexExecutorImpl(dataContext));
for (Materialization materialization : materializations) {
planner.addMaterialization(
new RelOptMaterialization(materialization.tableRel,
materialization.queryRel,
materialization.starRelOptTable));
}
final RelNode rootRel2 =
planner.changeTraits(rel, requiredOutputTraits);
assert rootRel2 != null;
planner.setRoot(rootRel2);
final RelOptPlanner planner2 = planner.chooseDelegate();
final RelNode rootRel3 = planner2.findBestExp();
assert rootRel3 != null : "could not implement exp";
return rootRel3;
}
};
final RelNode rootRel3 = program1.run(planner, rootRel, desiredTraits);
// Second planner pass to do physical "tweaks". This the first time that
// EnumerableCalcRel is introduced.
final Program program2 =
Programs.hep(CALC_RULES, true, new DefaultRelMetadataProvider());
final RelNode rootRel4 = program2.run(null, rootRel3, null);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(
"Plan after physical tweaks: "
+ RelOptUtil.toString(rootRel4, SqlExplainLevel.ALL_ATTRIBUTES));
}