Skip to content

Commit

Permalink
DRILL-4771: Drill should avoid doing the same join twice if count(dis…
Browse files Browse the repository at this point in the history
…tinct) exists

close #588
  • Loading branch information
Gautam Parai authored and Aman Sinha committed Sep 20, 2016
1 parent 140304d commit 2295715
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -1446,7 +1446,7 @@
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>1.4.0-drill-r17</version>
<version>1.4.0-drill-r18</version>
<exclusions>
<exclusion>
<groupId>org.jgrapht</groupId>
Expand Down

0 comments on commit 2295715

Please sign in to comment.