Hi,

I am trying to create a two stage planner using HepPlanner and then
VolcanoPlanner

Which is the correct sequence of steps to pass from SQL to Enumerable ?
My goal is to use Hep for very simple queries like simple INSERTs, SELECT *
FROM TABLE, SELECT * FROM TABLE WHERE pk=?....
Volcano is overkill for such stuff.

This is my idea:
1) get a Planner (that's Volcano)
Planner planner = Frameworks.getPlanner(config);

2) Get the logical plan
 SqlNode n = planner.parse(query);
            n = planner.validate(n);
            RelNode logicalPlan = planner.rel(n).project();
3) Create HepPlanner
HepProgram hepProgram =
                    HepProgram.
                            builder()
                            . ?? which Rules ?
                            .build();

            HepPlanner hepPlanner = new HepPlanner(hepProgram);
            hepPlanner.addRelTraitDef(ConventionTraitDef.INSTANCE);

            hepPlanner.setRoot(logicalPlan);

4) Run HepPlanner
RelNode bestForHep = hepPlanner.findBestExp();

5) Pick Volcano

final RelOptPlanner optPlanner = cluster.getPlanner();

6) Convert to Enumerable

final RelOptPlanner optPlanner = cluster.getPlanner();

            optPlanner.addRule(CoreRules.FILTER_REDUCE_EXPRESSIONS);
            RelTraitSet desiredTraits =
                    cluster.traitSet()
                            .replace(EnumerableConvention.INSTANCE);
            final RelCollation collation =
                    logicalPlan instanceof Sort
                            ? ((Sort) logicalPlan).collation
                            : null;
            if (collation != null) {
                desiredTraits = desiredTraits.replace(collation);
            }
            final RelNode newRoot = optPlanner.changeTraits(logicalPlan,
desiredTraits);
            optPlanner.setRoot(newRoot);
            RelNode bestExp = optPlanner.findBestExp();

Any hint/pointer is very appreciated

The alternative is to detect such simple queries and use a little set of
Rules and not Programs.ofRules(Programs.RULE_SET)

Best regards
Enrico

Reply via email to