[ 
https://issues.apache.org/jira/browse/BEAM-4388?focusedWorklogId=108670&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-108670
 ]

ASF GitHub Bot logged work on BEAM-4388:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jun/18 17:11
            Start Date: 04/Jun/18 17:11
    Worklog Time Spent: 10m 
      Work Description: kennknowles commented on a change in pull request 
#5481: [BEAM-4388] Support optimized logical plan
URL: https://github.com/apache/beam/pull/5481#discussion_r192815781
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/BeamQueryPlanner.java
 ##########
 @@ -131,12 +139,42 @@ BeamRelNode convertToBeamRel(String sqlStatement)
               .replace(BeamLogicalConvention.INSTANCE)
               .replace(root.collation)
               .simplify();
-      beamRelNode = (BeamRelNode) planner.transform(0, desiredTraits, 
root.rel);
-      LOG.info("BeamSQL>\n" + RelOptUtil.toString(beamRelNode));
+
+      // original logical plan
+      RelNode originalRelNode = planner.transform(0, desiredTraits, root.rel);
+
+      // optimized logical plan
+      beamRelNode = optimizeLogicPlan(originalRelNode, desiredTraits);
+      LOG.info("OptimizedPlan>\n" + RelOptUtil.toString(beamRelNode));
     } finally {
       planner.close();
     }
-    return beamRelNode;
+    return (BeamRelNode) beamRelNode;
+  }
+
+  /** execute volcano planner. */
+  private RelNode runVolcanoPlanner(
+      RuleSet logicalOptRuleSet, RelNode relNode, RelTraitSet 
logicalOptTraitSet)
+      throws CannotPlanException {
+    Program optProgram = Programs.ofRules(logicalOptRuleSet);
+
+    try {
+      return optProgram.run(
+          relNode.getCluster().getPlanner(),
+          relNode,
+          logicalOptTraitSet,
+          Collections.EMPTY_LIST,
+          Collections.EMPTY_LIST);
+    } catch (CannotPlanException e) {
+      throw e;
+    }
+  }
+
+  private RelNode optimizeLogicPlan(RelNode relNode, RelTraitSet desiredTraits)
+      throws CannotPlanException {
+    RuleSet logicalOptRuleSet = BeamRuleSets.getRuleSets()[0];
 
 Review comment:
   I was actually incorrect about how things work. It is nice to keep the sets 
of rules separate, but we probably do just want to put them all in the same 
bucket and run them together through our existing code paths.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 108670)
    Time Spent: 2h 10m  (was: 2h)

> Support optimized logical plan
> ------------------------------
>
>                 Key: BEAM-4388
>                 URL: https://issues.apache.org/jira/browse/BEAM-4388
>             Project: Beam
>          Issue Type: Sub-task
>          Components: dsl-sql
>            Reporter: Kai Jiang
>            Assignee: Kai Jiang
>            Priority: Major
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> Before converting into Beam Pipeline physical plan, logical plan should be 
> optimized and it will be super helpful for efficiently executing Beam 
> PTransforms pipeline. 
> Calcite has two ways for optimizing logical plan (HepPlanner and 
> VolcanoPlanner). We can support VolcanoPlanner first and apply calcite 
> builtin optimize rules (like 
> FilterJoinRule.FILTER_ON_JOIN) to sql query optimize plans.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to