drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject drill git commit: DRILL-3414: Make sure to walk entire expression tree when rewriting filter expression for pruning
Date Tue, 30 Jun 2015 00:13:10 GMT
Repository: drill
Updated Branches:
  refs/heads/master 2b5c52e57 -> 19c0225dc


DRILL-3414: Make sure to walk entire expression tree when rewriting filter expression for
pruning


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

Branch: refs/heads/master
Commit: 19c0225dcf25cbf19eca05be79b801309f91f4b6
Parents: 2b5c52e
Author: Steven Phillips <smp@apache.org>
Authored: Mon Jun 29 13:37:55 2015 -0700
Committer: Steven Phillips <smp@apache.org>
Committed: Mon Jun 29 17:08:33 2015 -0700

----------------------------------------------------------------------
 .../partition/RewriteAsBinaryOperators.java     | 31 +++++++++++++++-----
 .../RewriteCombineBinaryOperators.java          | 19 +++++++++++-
 .../apache/drill/TestCTASPartitionFilter.java   | 20 +++++++++++++
 3 files changed, 62 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/19c0225d/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteAsBinaryOperators.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteAsBinaryOperators.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteAsBinaryOperators.java
index 44b9a3a..95432c9 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteAsBinaryOperators.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteAsBinaryOperators.java
@@ -17,6 +17,9 @@
   */
 package org.apache.drill.exec.planner.logical.partition;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexCorrelVariable;
@@ -24,6 +27,7 @@ import org.apache.calcite.rex.RexDynamicParam;
 import org.apache.calcite.rex.RexFieldAccess;
 import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexLocalRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexOver;
 import org.apache.calcite.rex.RexRangeRef;
@@ -74,16 +78,24 @@ import java.util.List;
   public RexNode visitCall(RexCall call) {
     SqlOperator op = call.getOperator();
     SqlKind kind = op.getKind();
+    RelDataType type = call.getType();
     if (kind == SqlKind.OR || kind == SqlKind.AND) {
-      if (call.getOperands().size() <= 2) {
-        return call;
+      if (call.getOperands().size() > 2) {
+        List<RexNode> children = new ArrayList(call.getOperands());
+        RexNode left = children.remove(0).accept(this);
+        RexNode right = builder.makeCall(type, op, children).accept(this);
+        return builder.makeCall(type, op, ImmutableList.of(left, right));
       }
-      List<RexNode> children = new ArrayList(call.getOperands());
-      RexNode left = children.remove(0);
-      RexNode right = builder.makeCall(op, children).accept(this);
-      return builder.makeCall(op, left, right);
     }
-    return call;
+    return builder.makeCall(type, op, visitChildren(call));
+  }
+
+  private List<RexNode> visitChildren(RexCall call) {
+    List<RexNode> children = Lists.newArrayList();
+    for (RexNode child : call.getOperands()) {
+      children.add(child.accept(this));
+    }
+    return ImmutableList.copyOf(children);
   }
 
   @Override
@@ -100,4 +112,9 @@ import java.util.List;
   public RexNode visitFieldAccess(RexFieldAccess fieldAccess) {
     return fieldAccess;
   }
+
+  @Override
+  public RexNode visitLocalRef(RexLocalRef localRef) {
+    return localRef;
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/19c0225d/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteCombineBinaryOperators.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteCombineBinaryOperators.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteCombineBinaryOperators.java
index 247ad8f..be818d3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteCombineBinaryOperators.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/RewriteCombineBinaryOperators.java
@@ -17,8 +17,10 @@
   */
 package org.apache.drill.exec.planner.logical.partition;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.rex.RexCall;
 import org.apache.calcite.rex.RexCorrelVariable;
@@ -26,6 +28,7 @@ import org.apache.calcite.rex.RexDynamicParam;
 import org.apache.calcite.rex.RexFieldAccess;
 import org.apache.calcite.rex.RexInputRef;
 import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexLocalRef;
 import org.apache.calcite.rex.RexNode;
 import org.apache.calcite.rex.RexOver;
 import org.apache.calcite.rex.RexRangeRef;
@@ -76,6 +79,7 @@ import java.util.List;
   public RexNode visitCall(RexCall call) {
     SqlOperator op = call.getOperator();
     SqlKind kind = op.getKind();
+    RelDataType type = call.getType();
     if (kind == SqlKind.AND) {
       List<RexNode> conjuncts = Lists.newArrayList();
       for (RexNode child : call.getOperands()) {
@@ -90,7 +94,15 @@ import java.util.List;
       }
       return RexUtil.composeDisjunction(builder, disjuncts, true);
     }
-    return call;
+    return builder.makeCall(type, op, visitChildren(call));
+  }
+
+  private List<RexNode> visitChildren(RexCall call) {
+    List<RexNode> children = Lists.newArrayList();
+    for (RexNode child : call.getOperands()) {
+      children.add(child.accept(this));
+    }
+    return ImmutableList.copyOf(children);
   }
 
   @Override
@@ -107,4 +119,9 @@ import java.util.List;
   public RexNode visitFieldAccess(RexFieldAccess fieldAccess) {
     return fieldAccess;
   }
+
+  @Override
+  public RexNode visitLocalRef(RexLocalRef localRef) {
+    return localRef;
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/19c0225d/exec/java-exec/src/test/java/org/apache/drill/TestCTASPartitionFilter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestCTASPartitionFilter.java b/exec/java-exec/src/test/java/org/apache/drill/TestCTASPartitionFilter.java
index 48d7ceb..9886024 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestCTASPartitionFilter.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestCTASPartitionFilter.java
@@ -76,4 +76,24 @@ public class TestCTASPartitionFilter extends PlanTestBase {
     String query = "select * from drill_3410 where (o_orderpriority = '1-URGENT' and o_orderkey
= 10) or (o_orderpriority = '2-HIGH' or o_orderkey = 11)";
     testIncludeFilter(query, 1, "Filter", 34);
   }
+
+  @Test
+  public void testDRILL3414() throws Exception {
+    test("alter session set `planner.slice_target` = 1");
+    test("alter session set `store.partition.hash_distribute` = true");
+    test("use dfs_test.tmp");
+    test(String.format("create table drill_3414 partition by (dir0, dir1) as select * from
dfs_test.`%s/multilevel/csv`", TEST_RES_PATH));
+    String query = ("select * from drill_3414 where (dir0=1994 or dir1='Q1') and (dir0=1995
or dir1='Q2' or columns[0] > 5000)");
+    testIncludeFilter(query, 6, "Filter", 20);
+  }
+
+  @Test
+  public void testDRILL3414_2() throws Exception {
+    test("alter session set `planner.slice_target` = 1");
+    test("alter session set `store.partition.hash_distribute` = true");
+    test("use dfs_test.tmp");
+    test(String.format("create table drill_3414_2 partition by (dir0, dir1) as select * from
dfs_test.`%s/multilevel/csv`", TEST_RES_PATH));
+    String query = ("select * from drill_3414_2 where (dir0=1994 or dir1='Q1') and (dir0=1995
or dir1='Q2' or columns[0] > 5000) or columns[0] < 3000");
+    testIncludeFilter(query, 1, "Filter", 120);
+  }
 }
\ No newline at end of file


Mime
View raw message