From 1ce36fc0361cd581fffd666370393b1ff27d2ffe Mon Sep 17 00:00:00 2001 From: Gautam Parai Date: Mon, 12 Sep 2016 20:21:46 -0700 Subject: [PATCH] DRILL-4771: Drill should avoid doing the same join twice if count(distinct) exists --- .../java/org/apache/drill/TestBugFixes.java | 33 +++++++++++++++++++ pom.xml | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java index c5062b2d576..5b736bc817c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java @@ -167,4 +167,37 @@ public void testDRILL4192() throws Exception { .baselineValues("single_top_partition", "nested_partition_1") .go(); } + + @Test + public void testDRILL4771() throws Exception { + final String query = "select count(*) cnt, avg(distinct emp.department_id) avd\n" + + " from cp.`employee.json` emp"; + final String[] expectedPlans = { + ".*Agg\\(group=\\[\\{\\}\\], cnt=\\[\\$SUM0\\(\\$1\\)\\], agg#1=\\[\\$SUM0\\(\\$0\\)\\], agg#2=\\[COUNT\\(\\$0\\)\\]\\)", + ".*Agg\\(group=\\[\\{0\\}\\], cnt=\\[COUNT\\(\\)\\]\\)"}; + final String[] excludedPlans = {".*Join\\(condition=\\[true\\], joinType=\\[inner\\]\\).*"}; + PlanTestBase.testPlanMatchingPatterns(query, expectedPlans, excludedPlans); + testBuilder() + .sqlQuery(query) + .unOrdered() + .baselineColumns("cnt", "avd") + .baselineValues(1155L, 10.416666666666666) + .build().run(); + + final String query1 = "select emp.gender, count(*) cnt, avg(distinct emp.department_id) avd\n" + + " from cp.`employee.json` emp\n" + + " group by gender"; + final String[] expectedPlans1 = { + ".*Agg\\(group=\\[\\{0\\}\\], agg#0=\\[\\$SUM0\\(\\$2\\)\\], agg#1=\\[\\$SUM0\\(\\$1\\)\\], agg#2=\\[COUNT\\(\\$1\\)\\]\\)", + ".*Agg\\(group=\\[\\{0, 1\\}\\], cnt=\\[COUNT\\(\\)\\]\\)"}; + final String[] excludedPlans1 = {".*Join\\(condition=\\[true\\], joinType=\\[inner\\]\\).*"}; + PlanTestBase.testPlanMatchingPatterns(query1, expectedPlans1, excludedPlans1); + testBuilder() + .sqlQuery(query1) + .unOrdered() + .baselineColumns("gender", "cnt", "avd") + .baselineValues("F", 601L, 10.416666666666666) + .baselineValues("M", 554L, 11.9) + .build().run(); + } } diff --git a/pom.xml b/pom.xml index decfcbc1ef5..0768720da5f 100644 --- a/pom.xml +++ b/pom.xml @@ -1446,7 +1446,7 @@ org.apache.calcite calcite-core - 1.4.0-drill-r17 + 1.4.0-drill-r18 org.jgrapht