drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [1/3] drill git commit: DRILL-2400: Part 2: Add merge filter rule to logical rule sets. Increase function cost differentials.
Date Sat, 07 Mar 2015 06:46:45 GMT
Repository: drill
Updated Branches:
  refs/heads/master fe94970e1 -> 6be9e3b1e


DRILL-2400: Part 2: Add merge filter rule to logical rule sets.  Increase function cost differentials.


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

Branch: refs/heads/master
Commit: 6be9e3b1e51e2ade87066d0d26c4e43426500c62
Parents: 6e6f789
Author: Jacques Nadeau <jacques@apache.org>
Authored: Sun Feb 15 14:17:20 2015 -0800
Committer: Jinfeng Ni <jni@maprtech.com>
Committed: Fri Mar 6 22:19:21 2015 -0800

----------------------------------------------------------------------
 .../exec/expr/annotations/FunctionTemplate.java |   2 +-
 .../planner/logical/DrillMergeFilterRule.java   | 101 +++++++++++++++++++
 .../exec/planner/logical/DrillRuleSets.java     |   7 +-
 3 files changed, 108 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/6be9e3b1/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
index 15c7e19..7cafab5 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java
@@ -94,7 +94,7 @@ public @interface FunctionTemplate {
   }
 
   public static enum FunctionCostCategory {
-    SIMPLE(1), MEDIUM(3), COMPLEX(5);
+    SIMPLE(1), MEDIUM(20), COMPLEX(50);
 
     private final int value;
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6be9e3b1/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillMergeFilterRule.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillMergeFilterRule.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillMergeFilterRule.java
new file mode 100644
index 0000000..b406cfb
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillMergeFilterRule.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.logical;
+
+import org.eigenbase.rel.FilterRel;
+import org.eigenbase.relopt.RelOptRule;
+import org.eigenbase.relopt.RelOptRuleCall;
+import org.eigenbase.rex.RexBuilder;
+import org.eigenbase.rex.RexCall;
+import org.eigenbase.rex.RexNode;
+import org.eigenbase.rex.RexProgram;
+import org.eigenbase.rex.RexProgramBuilder;
+import org.eigenbase.rex.RexUtil;
+
+/**
+ * MergeFilterRule implements the rule for combining two {@link FilterRel}s
+ */
+public class DrillMergeFilterRule extends RelOptRule {
+  public static final DrillMergeFilterRule INSTANCE = new DrillMergeFilterRule();
+
+  //~ Constructors -----------------------------------------------------------
+
+  /**
+   * Creates a MergeFilterRule.
+   */
+  private DrillMergeFilterRule() {
+    super(
+        operand(
+            FilterRel.class,
+            operand(FilterRel.class, any())));
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  // implement RelOptRule
+  public void onMatch(RelOptRuleCall call) {
+    FilterRel topFilter = call.rel(0);
+    FilterRel bottomFilter = call.rel(1);
+
+    // use RexPrograms to merge the two FilterRels into a single program
+    // so we can convert the two FilterRel conditions to directly
+    // reference the bottom FilterRel's child
+    RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
+    RexProgram bottomProgram = createProgram(bottomFilter);
+    RexProgram topProgram = createProgram(topFilter);
+
+    RexProgram mergedProgram =
+        RexProgramBuilder.mergePrograms(
+            topProgram,
+            bottomProgram,
+            rexBuilder);
+
+    RexNode newCondition =
+        mergedProgram.expandLocalRef(
+            mergedProgram.getCondition());
+
+    if(!RexUtil.isFlat(newCondition)){
+      RexCall newCall = (RexCall) newCondition;
+      newCondition = rexBuilder.makeFlatCall( newCall.getOperator(), newCall.getOperands());
+    }
+
+    FilterRel newFilterRel =
+        new FilterRel(
+            topFilter.getCluster(),
+            bottomFilter.getChild(),
+            newCondition);
+
+    call.transformTo(newFilterRel);
+  }
+
+  /**
+   * Creates a RexProgram corresponding to a FilterRel
+   *
+   * @param filterRel the FilterRel
+   * @return created RexProgram
+   */
+  private RexProgram createProgram(FilterRel filterRel) {
+    RexProgramBuilder programBuilder =
+        new RexProgramBuilder(
+            filterRel.getRowType(),
+            filterRel.getCluster().getRexBuilder());
+    programBuilder.addIdentity();
+    programBuilder.addCondition(filterRel.getCondition());
+    return programBuilder.getProgram();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6be9e3b1/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 389395c..9c59a9e 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
@@ -42,6 +42,8 @@ import org.apache.drill.exec.planner.physical.WindowPrule;
 import org.apache.drill.exec.planner.physical.UnionAllPrule;
 import org.apache.drill.exec.planner.physical.WriterPrule;
 import org.eigenbase.rel.RelFactories;
+import org.eigenbase.rel.rules.MergeFilterRule;
+import org.eigenbase.rel.rules.MergeProjectRule;
 import org.eigenbase.rel.rules.PushFilterPastJoinRule;
 import org.eigenbase.rel.rules.PushJoinThroughJoinRule;
 import org.eigenbase.rel.rules.RemoveDistinctAggregateRule;
@@ -72,7 +74,7 @@ public class DrillRuleSets {
       // End support for WHERE style joins.
 
       //Add back rules
-
+      DrillMergeFilterRule.INSTANCE,
       ExpandConversionRule.INSTANCE,
 //      SwapJoinRule.INSTANCE,
       RemoveDistinctRule.INSTANCE,
@@ -144,6 +146,9 @@ public class DrillRuleSets {
     ruleList.add(WindowPrule.INSTANCE);
     ruleList.add(PushLimitToTopN.INSTANCE);
     ruleList.add(UnionAllPrule.INSTANCE);
+
+
+
     // ruleList.add(UnionDistinctPrule.INSTANCE);
 
     PlannerSettings ps = qcontext.getPlannerSettings();


Mime
View raw message