You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by am...@apache.org on 2015/03/28 08:47:27 UTC
drill git commit: DRILL-2568: Drop filter plan node if all conjuncts
have been pushed into the scan as part of partition pruning.
Repository: drill
Updated Branches:
refs/heads/master 20efb2fbc -> c11fcf73f
DRILL-2568: Drop filter plan node if all conjuncts have been pushed into the scan as part of partition pruning.
Check presence in children list before adding..
Split prune condition into conjuncts before removing from the original condition. Add plan checking and row count validation to TestPartitionFilter tests.
Move more tests from TestPrune into TestPartitionFilter and added plan checking and results validation.
Remove TestPrune since these tests Are subsumed by the ones in TestPartitionFilter.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/c11fcf73
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/c11fcf73
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/c11fcf73
Branch: refs/heads/master
Commit: c11fcf73fe16e7d5bb976607ecf4fb1bf70a7aec
Parents: 20efb2f
Author: Aman Sinha <as...@maprtech.com>
Authored: Wed Mar 25 18:25:08 2015 -0700
Committer: Aman Sinha <as...@maprtech.com>
Committed: Sat Mar 28 00:20:12 2015 -0700
----------------------------------------------------------------------
.../partition/FindPartitionConditions.java | 4 +-
.../logical/partition/PruneScanRule.java | 16 ++-
.../org/apache/drill/TestPartitionFilter.java | 111 ++++++++++++-------
.../org/apache/drill/exec/expr/TestPrune.java | 47 --------
4 files changed, 88 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/c11fcf73/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/FindPartitionConditions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/FindPartitionConditions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/FindPartitionConditions.java
index 3acf29d..5cf360a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/FindPartitionConditions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/FindPartitionConditions.java
@@ -71,7 +71,9 @@ public class FindPartitionConditions extends RexVisitorImpl<Void> {
return booleanOp;
}
public void addChild(RexNode n) {
- children.add(n);
+ if (!children.contains(n)) {
+ children.add(n);
+ }
}
public List<RexNode> getChildren() {
return children;
http://git-wip-us.apache.org/repos/asf/drill/blob/c11fcf73/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/PruneScanRule.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/PruneScanRule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/PruneScanRule.java
index 413259d..5fab35a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/PruneScanRule.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/partition/PruneScanRule.java
@@ -58,6 +58,7 @@ import org.eigenbase.relopt.RelOptRuleCall;
import org.eigenbase.relopt.RelOptRuleOperand;
import org.eigenbase.relopt.RelOptUtil;
import org.eigenbase.rex.RexNode;
+import org.eigenbase.rex.RexUtil;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
@@ -232,8 +233,11 @@ public abstract class PruneScanRule extends RelOptRule {
}
}
+ boolean canDropFilter = true;
+
if(newFiles.isEmpty()){
newFiles.add(files.get(0));
+ canDropFilter = false;
}
if(newFiles.size() == files.size()){
@@ -242,6 +246,10 @@ public abstract class PruneScanRule extends RelOptRule {
logger.debug("Pruned {} => {}", files, newFiles);
+ List<RexNode> conjuncts = RelOptUtil.conjunctions(condition);
+ List<RexNode> pruneConjuncts = RelOptUtil.conjunctions(pruneCondition);
+ conjuncts.removeAll(pruneConjuncts);
+ RexNode newCondition = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), conjuncts, false);
final FileSelection newFileSelection = new FileSelection(newFiles, origSelection.getSelection().selectionRoot, true);
final FileGroupScan newScan = ((FileGroupScan)scanRel.getGroupScan()).clone(newFileSelection);
@@ -259,8 +267,12 @@ public abstract class PruneScanRule extends RelOptRule {
inputRel = projectRel.copy(projectRel.getTraitSet(), Collections.singletonList(inputRel));
}
- final RelNode newFilter = filterRel.copy(filterRel.getTraitSet(), Collections.singletonList(inputRel));
- call.transformTo(newFilter);
+ if (newCondition.isAlwaysTrue() && canDropFilter) {
+ call.transformTo(inputRel);
+ } else {
+ final RelNode newFilter = filterRel.copy(filterRel.getTraitSet(), Collections.singletonList(inputRel));
+ call.transformTo(newFilter);
+ }
}catch(Exception e){
logger.warn("Exception while trying to prune partition.", e);
http://git-wip-us.apache.org/repos/asf/drill/blob/c11fcf73/exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java b/exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java
index 6b904ec..400847d 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java
@@ -17,79 +17,86 @@
*/
package org.apache.drill;
+
+import static org.junit.Assert.assertEquals;
+
import org.apache.drill.common.util.TestTools;
import org.junit.Test;
-public class TestPartitionFilter extends BaseTestQuery{
+public class TestPartitionFilter extends PlanTestBase {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestPartitionFilter.class);
static final String WORKING_PATH = TestTools.getWorkingPath();
static final String TEST_RES_PATH = WORKING_PATH + "/src/test/resources";
- @Test //Parquet: basic test with dir0 and dir1 filters in different orders
+ private static void testExcludeFilter(String query, int expectedNumFiles,
+ String excludedFilterPattern, int expectedRowCount) throws Exception {
+ int actualRowCount = testSql(query);
+ assertEquals(expectedRowCount, actualRowCount);
+ String numFilesPattern = "numFiles=" + expectedNumFiles;
+ testPlanMatchingPatterns(query, new String[]{numFilesPattern}, new String[]{excludedFilterPattern});
+ }
+
+ private static void testIncludeFilter(String query, int expectedNumFiles,
+ String includedFilterPattern, int expectedRowCount) throws Exception {
+ int actualRowCount = testSql(query);
+ assertEquals(expectedRowCount, actualRowCount);
+ String numFilesPattern = "numFiles=" + expectedNumFiles;
+ testPlanMatchingPatterns(query, new String[]{numFilesPattern, includedFilterPattern}, new String[]{});
+ }
+
+ @Test //Parquet: basic test with dir0 and dir1 filters
public void testPartitionFilter1_Parquet() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir1='Q1' and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testExcludeFilter(query, 1, "Filter", 10);
}
- @Test //Json: basic test with dir0 and dir1 filters in different orders
+ @Test //Json: basic test with dir0 and dir1 filters
public void testPartitionFilter1_Json() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir1='Q1' and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testExcludeFilter(query, 1, "Filter", 10);
}
- @Test //CSV: basic test with dir0 and dir1 filters in different orders
+ @Test //CSV: basic test with dir0 and dir1 filters in
public void testPartitionFilter1_Csv() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/csv` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select * from dfs_test.`%s/multilevel/csv` where dir1='Q1' and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select * from dfs_test.`%s/multilevel/csv` where dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testExcludeFilter(query, 1, "Filter", 10);
}
@Test //Parquet: partition filters are combined with regular columns in an AND
public void testPartitionFilter2_Parquet() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where o_custkey < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir1='Q1' and o_custkey < 1000 and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where o_custkey < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testIncludeFilter(query, 1, "Filter", 5);
}
@Test //Json: partition filters are combined with regular columns in an AND
public void testPartitionFilter2_Json() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where o_custkey < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir1='Q1' and o_custkey < 1000 and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where o_custkey < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testIncludeFilter(query, 1, "Filter", 5);
}
@Test //CSV: partition filters are combined with regular columns in an AND
public void testPartitionFilter2_Csv() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/csv` where columns[1] < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
- String query2 = String.format("select * from dfs_test.`%s/multilevel/csv` where dir1='Q1' and columns[1] < 1000 and dir0=1994", TEST_RES_PATH);
- test(query1);
- test(query2);
+ String query = String.format("select * from dfs_test.`%s/multilevel/csv` where columns[1] < 1000 and dir0=1994 and dir1='Q1'", TEST_RES_PATH);
+ testIncludeFilter(query, 1, "Filter", 5);
}
@Test //Parquet: partition filters are ANDed and belong to a top-level OR
public void testPartitionFilter3_Parquet() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/parquet` where (dir0=1994 and dir1='Q1' and o_custkey < 500) or (dir0=1995 and dir1='Q2' and o_custkey > 500)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select * from dfs_test.`%s/multilevel/parquet` where (dir0=1994 and dir1='Q1' and o_custkey < 500) or (dir0=1995 and dir1='Q2' and o_custkey > 500)", TEST_RES_PATH);
+ testIncludeFilter(query, 2, "Filter", 8);
}
@Test //Json: partition filters are ANDed and belong to a top-level OR
public void testPartitionFilter3_Json() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/json` where (dir0=1994 and dir1='Q1' and o_custkey < 500) or (dir0=1995 and dir1='Q2' and o_custkey > 500)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select * from dfs_test.`%s/multilevel/json` where (dir0=1994 and dir1='Q1' and o_custkey < 500) or (dir0=1995 and dir1='Q2' and o_custkey > 500)", TEST_RES_PATH);
+ testIncludeFilter(query, 2, "Filter", 8);
}
@Test //CSV: partition filters are ANDed and belong to a top-level OR
public void testPartitionFilter3_Csv() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/csv` where (dir0=1994 and dir1='Q1' and columns[1] < 500) or (dir0=1995 and dir1='Q2' and columns[1] > 500)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select * from dfs_test.`%s/multilevel/csv` where (dir0=1994 and dir1='Q1' and columns[1] < 500) or (dir0=1995 and dir1='Q2' and columns[1] > 500)", TEST_RES_PATH);
+ testIncludeFilter(query, 2, "Filter", 8);
}
@Test //Parquet: filters contain join conditions and partition filters
@@ -112,20 +119,44 @@ public class TestPartitionFilter extends BaseTestQuery{
@Test // Parquet: IN filter
public void testPartitionFilter5_Parquet() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir0 in (1995, 1996)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/parquet` where dir0 in (1995, 1996)", TEST_RES_PATH);
+ testExcludeFilter(query, 8, "Filter", 80);
}
@Test // Json: IN filter
public void testPartitionFilter5_Json() throws Exception {
- String query1 = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir0 in (1995, 1996)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select dir0, dir1, o_custkey, o_orderdate from dfs_test.`%s/multilevel/json` where dir0 in (1995, 1996)", TEST_RES_PATH);
+ testExcludeFilter(query, 8, "Filter", 80);
}
@Test // CSV: IN filter
public void testPartitionFilter5_Csv() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/multilevel/csv` where dir0 in (1995, 1996)", TEST_RES_PATH);
- test(query1);
+ String query = String.format("select * from dfs_test.`%s/multilevel/csv` where dir0 in (1995, 1996)", TEST_RES_PATH);
+ testExcludeFilter(query, 8, "Filter", 80);
+ }
+
+ @Test // Parquet: one side of OR has partition filter only, other side has both partition filter and non-partition filter
+ public void testPartitionFilter6_Parquet() throws Exception {
+ String query = String.format("select * from dfs_test.`%s/multilevel/parquet` where (dir0=1995 and o_totalprice < 40000) or dir0=1996", TEST_RES_PATH);
+ testIncludeFilter(query, 8, "Filter", 46);
+ }
+
+ @Test // Parquet: trivial case with 1 partition filter
+ public void testPartitionFilter7_Parquet() throws Exception {
+ String query = String.format("select * from dfs_test.`%s/multilevel/parquet` where dir0=1995", TEST_RES_PATH);
+ testExcludeFilter(query, 4, "Filter", 40);
+ }
+
+ @Test // Parquet: partition filter on subdirectory only
+ public void testPartitionFilter8_Parquet() throws Exception {
+ String query = String.format("select * from dfs_test.`%s/multilevel/parquet` where dir1 in ('Q1','Q4')", TEST_RES_PATH);
+ testExcludeFilter(query, 6, "Filter", 60);
+ }
+
+ @Test // Parquet: partition filter on subdirectory only plus non-partition filter
+ public void testPartitionFilter9_Parquet() throws Exception {
+ String query = String.format("select * from dfs_test.`%s/multilevel/parquet` where dir1 in ('Q1','Q4') and o_totalprice < 40000", TEST_RES_PATH);
+ testIncludeFilter(query, 6, "Filter", 9);
}
}
http://git-wip-us.apache.org/repos/asf/drill/blob/c11fcf73/exec/java-exec/src/test/java/org/apache/drill/exec/expr/TestPrune.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/TestPrune.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/TestPrune.java
deleted file mode 100644
index d15555e..0000000
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/TestPrune.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * 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.expr;
-
-import org.apache.drill.BaseTestQuery;
-import org.apache.drill.common.util.TestTools;
-import org.junit.Test;
-
-public class TestPrune extends BaseTestQuery {
-
- String MULTILEVEL = TestTools.getWorkingPath() + "/../java-exec/src/test/resources/multilevel";
-
- @Test
- public void pruneCompound1() throws Exception {
- test(String.format("select * from dfs.`%s/csv` where x is null and dir1 in ('Q1', 'Q2')", MULTILEVEL));
- }
-
- @Test
- public void pruneSimple1() throws Exception {
- test(String.format("select * from dfs.`%s/csv` where dir1 in ('Q1', 'Q2')", MULTILEVEL));
- }
-
- @Test
- public void pruneCompound2() throws Exception {
- String query1 = String.format("select * from dfs_test.`%s/parquet` where (dir0=1995 and o_totalprice < 40000) or (dir0=1996 and o_totalprice < 40000)", MULTILEVEL);
- String query2 = String.format("select * from dfs_test.`%s/parquet` where dir0=1995 and o_totalprice < 40000", MULTILEVEL);
- String query3 = String.format("select * from dfs_test.`%s/parquet` where (dir0=1995 and o_totalprice < 40000) or dir0=1996", MULTILEVEL);
- String query4 = String.format("select * from dfs_test.`%s/parquet` where dir0=1995 or dir0=1996", MULTILEVEL);
- test(query3);
- }
-
-}