Repository: drill Updated Branches: refs/heads/master 5bd92f832 -> 974c6f2bf
DRILL-2852: Examine the input of a CAST function when traversing the expression tree for finding directory filters. Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/974c6f2b Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/974c6f2b Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/974c6f2b Branch: refs/heads/master Commit: 974c6f2bf3aa52e2fcd565e5290cb0828ba59933 Parents: 5bd92f8 Author: Aman Sinha <[email protected]> Authored: Mon Aug 3 16:08:54 2015 -0700 Committer: Aman Sinha <[email protected]> Committed: Tue Aug 4 15:52:03 2015 -0700 ---------------------------------------------------------------------- .../partition/FindPartitionConditions.java | 18 ++++++++++++++++-- .../org/apache/drill/TestPartitionFilter.java | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/974c6f2b/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 7dbadc9..fe874bd 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 @@ -35,6 +35,7 @@ import org.apache.calcite.rex.RexRangeRef; import org.apache.calcite.rex.RexVisitorImpl; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSyntax; import org.apache.calcite.sql.fun.SqlRowOperator; import org.apache.calcite.util.Util; @@ -217,8 +218,21 @@ public class FindPartitionConditions extends RexVisitorImpl<Void> { } public Void visitCall(RexCall call) { - // assume PUSH until proven otherwise - analyzeCall(call, PushDirFilter.PUSH); + boolean visited = false; + // examine the input of a CAST function; this could be extended for + // other functions in the future. + if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL && + call.getKind() == SqlKind.CAST) { + RexNode n = call.getOperands().get(0); + if (n instanceof RexInputRef) { + visitInputRef((RexInputRef) n); + visited = true; + } + } + if (!visited) { + // assume PUSH until proven otherwise + analyzeCall(call, PushDirFilter.PUSH); + } return null; } http://git-wip-us.apache.org/repos/asf/drill/blob/974c6f2b/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 44c59a0..6a8efbf 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 @@ -255,4 +255,15 @@ public class TestPartitionFilter extends PlanTestBase { String query = String.format("select * from (select dir0, o_custkey from dfs_test.`%s` where dir0='1994' and o_custkey = 10) t limit 0", root); testIncludeFilter(query, 4, "Filter", 0); } + + @Test // see DRILL-2852 and DRILL-3591 + public void testPartitionFilterWithCast() throws Exception { + String root = FileUtils.getResourceAsFile("/multilevel/parquet").toURI().toString(); + String query = String.format("select myyear, myquarter, o_totalprice from (select cast(dir0 as varchar(10)) as myyear, " + + " cast(dir1 as varchar(10)) as myquarter, o_totalprice from dfs_test.`%s`) where myyear = cast('1995' as varchar(10)) " + + " and myquarter = cast('Q2' as varchar(10)) and o_totalprice < 40000.0 order by o_totalprice", root); + + testIncludeFilter(query, 1, "Filter", 3); + } + } \ No newline at end of file
