drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject drill git commit: DRILL-3594: don't use first query's allocator for rest of drillbit's life closes #102
Date Wed, 05 Aug 2015 22:46:45 GMT
Repository: drill
Updated Branches:
  refs/heads/master 317b92e40 -> 4d967ede3


DRILL-3594: don't use first query's allocator for rest of drillbit's life
closes #102


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/4d967ede
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/4d967ede
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/4d967ede

Branch: refs/heads/master
Commit: 4d967ede3e3d77021702e82cc3a9396057e4910b
Parents: 317b92e
Author: Chris Westin <cwestin@yahoo.com>
Authored: Mon Aug 3 13:13:21 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Wed Aug 5 13:56:05 2015 -0700

----------------------------------------------------------------------
 .../exec/planner/logical/DrillRuleSets.java     | 102 ++++++++++---------
 1 file changed, 52 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/4d967ede/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
index 3f49498..4307757 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRuleSets.java
@@ -62,9 +62,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
 
 public class DrillRuleSets {
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillRuleSets.class);
-
-  public static RuleSet DRILL_BASIC_RULES = null;
+  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillRuleSets.class);
 
   /**
    * Get a list of logical rules that can be turned on or off by session/system options.
@@ -80,11 +78,11 @@ public class DrillRuleSets {
    *         rules that have been turned off by system or session settings
    */
   public static RuleSet getDrillUserConfigurableLogicalRules(OptimizerRulesContext optimizerRulesContext)
{
-    PlannerSettings ps = optimizerRulesContext.getPlannerSettings();
+    final PlannerSettings ps = optimizerRulesContext.getPlannerSettings();
 
     // This list is used to store rules that can be turned on an off
     // by user facing planning options
-    Builder userConfigurableRules = ImmutableSet.<RelOptRule>builder();
+    final Builder<RelOptRule> userConfigurableRules = ImmutableSet.<RelOptRule>builder();
 
     if (ps.isConstantFoldingEnabled()) {
       // TODO - DRILL-2218
@@ -97,32 +95,11 @@ public class DrillRuleSets {
     return new DrillRuleSet(userConfigurableRules.build());
   }
 
-  /**
-   * Get an immutable list of rules that will always be used when running
-   * logical planning.
-   *
-   * This would be a static member, rather than a method, but some of
-   * the rules need a reference to state that isn't available at class
-   * load time. The current example is the DrillMergeProjectRule which
-   * needs access to the registry of Drill UDFs, which is populated by
-   * scanning the class path a Drillbit startup.
-   *
-   * If a logical rule needs to be user configurable, such as turning
-   * it on and off with a system/session option, add it in the
-   * getDrillUserConfigurableLogicalRules() method instead of here.
-   *
-   * @param optimizerRulesContext - shared state used during planning, currently used here
-   *                                to gain access to the function registry described above.
-   * @return - a RuleSet containing the logical rules that will always
-   *           be used, either by VolcanoPlanner directly, or
-   *           used VolcanoPlanner as pre-processing for LOPTPlanner.
-   *
-   * Note : Join permutation rule is excluded here.
+  /*
+   * These basic rules don't require any context, so singleton instances can be used.
+   * These are merged with per-query rules in getDrillBasicRules() below.
    */
-  public static RuleSet getDrillBasicRules(OptimizerRulesContext optimizerRulesContext) {
-    if (DRILL_BASIC_RULES == null) {
-
-      DRILL_BASIC_RULES = new DrillRuleSet(ImmutableSet.<RelOptRule> builder().add(
//
+  private final static ImmutableSet<RelOptRule> staticRuleSet = ImmutableSet.<RelOptRule>builder().add(
       // Add support for Distinct Union (by using Union-All followed by Distinct)
       UnionToDistinctRule.INSTANCE,
 
@@ -142,8 +119,6 @@ public class DrillRuleSets {
       ProjectRemoveRule.NAME_CALC_INSTANCE,
       SortRemoveRule.INSTANCE,
 
-      DrillMergeProjectRule.getInstance(true, RelFactories.DEFAULT_PROJECT_FACTORY,
-          optimizerRulesContext.getFunctionRegistry()),
       AggregateExpandDistinctAggregatesRule.INSTANCE,
       DrillReduceAggregatesRule.INSTANCE,
 
@@ -155,11 +130,6 @@ public class DrillRuleSets {
       DrillPushProjIntoScan.INSTANCE,
       DrillProjectSetOpTransposeRule.INSTANCE,
 
-      PruneScanRule.getFilterOnProject(optimizerRulesContext),
-      PruneScanRule.getFilterOnScan(optimizerRulesContext),
-      ParquetPruneScanRule.getFilterOnProjectParquet(optimizerRulesContext),
-      ParquetPruneScanRule.getFilterOnScanParquet(optimizerRulesContext),
-
       /*
        Convert from Calcite Logical to Drill Logical Rules.
        */
@@ -175,11 +145,46 @@ public class DrillRuleSets {
       DrillJoinRule.INSTANCE,
       DrillUnionAllRule.INSTANCE,
       DrillValuesRule.INSTANCE
-      )
-      .build());
-    }
+      ).build();
 
-    return DRILL_BASIC_RULES;
+  /**
+   * Get an immutable list of rules that will always be used when running
+   * logical planning.
+   *
+   * This cannot be a static singleton because some of the rules need to
+   * reference state owned by the current query (including its allocator).
+   *
+   * If a logical rule needs to be user configurable, such as turning
+   * it on and off with a system/session option, add it in the
+   * getDrillUserConfigurableLogicalRules() method instead of here.
+   *
+   * @param optimizerRulesContext - shared state used during planning, currently used here
+   *                                to gain access to the function registry described above.
+   * @return - a RuleSet containing the logical rules that will always
+   *           be used, either by VolcanoPlanner directly, or
+   *           used VolcanoPlanner as pre-processing for LOPTPlanner.
+   *
+   * Note : Join permutation rule is excluded here.
+   */
+  public static RuleSet getDrillBasicRules(OptimizerRulesContext optimizerRulesContext) {
+    /*
+     * We have to create another copy of the ruleset with the context dependent elements;
+     * this cannot be reused across queries.
+     */
+    final ImmutableSet<RelOptRule> basicRules = ImmutableSet.<RelOptRule>builder()
+        .addAll(staticRuleSet)
+        .add(
+            DrillMergeProjectRule.getInstance(true, RelFactories.DEFAULT_PROJECT_FACTORY,
+                optimizerRulesContext.getFunctionRegistry()),
+
+            PruneScanRule.getFilterOnProject(optimizerRulesContext),
+            PruneScanRule.getFilterOnScan(optimizerRulesContext),
+            ParquetPruneScanRule.getFilterOnProjectParquet(optimizerRulesContext),
+            ParquetPruneScanRule.getFilterOnScanParquet(optimizerRulesContext)
+            )
+        .build();
+
+    return new DrillRuleSet(basicRules);
   }
 
   // Ruleset for join permutation, used only in VolcanoPlanner.
@@ -190,15 +195,13 @@ public class DrillRuleSets {
         ).build());
   }
 
-  public static final RuleSet DRILL_PHYSICAL_DISK = new DrillRuleSet(ImmutableSet.of( //
+  public static final RuleSet DRILL_PHYSICAL_DISK = new DrillRuleSet(ImmutableSet.of(
       ProjectPrule.INSTANCE
-
     ));
 
   public static final RuleSet getPhysicalRules(OptimizerRulesContext optimizerRulesContext)
{
-    List<RelOptRule> ruleList = new ArrayList<RelOptRule>();
-
-    PlannerSettings ps = optimizerRulesContext.getPlannerSettings();
+    final List<RelOptRule> ruleList = new ArrayList<RelOptRule>();
+    final PlannerSettings ps = optimizerRulesContext.getPlannerSettings();
 
     ruleList.add(ConvertCountToDirectScan.AGG_ON_PROJ_ON_SCAN);
     ruleList.add(ConvertCountToDirectScan.AGG_ON_SCAN);
@@ -255,9 +258,9 @@ public class DrillRuleSets {
   }
 
   public static RuleSet mergedRuleSets(RuleSet...ruleSets) {
-    Builder<RelOptRule> relOptRuleSetBuilder = ImmutableSet.builder();
-    for (RuleSet ruleSet : ruleSets) {
-      for (RelOptRule relOptRule : ruleSet) {
+    final Builder<RelOptRule> relOptRuleSetBuilder = ImmutableSet.builder();
+    for (final RuleSet ruleSet : ruleSets) {
+      for (final RelOptRule relOptRule : ruleSet) {
         relOptRuleSetBuilder.add(relOptRule);
       }
     }
@@ -268,7 +271,6 @@ public class DrillRuleSets {
     final ImmutableSet<RelOptRule> rules;
 
     public DrillRuleSet(ImmutableSet<RelOptRule> rules) {
-      super();
       this.rules = rules;
     }
 


Mime
View raw message