drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject [7/7] drill git commit: DRILL-2309: Fix reduce aggregate rule to create new aggregate calls based on input row type
Date Wed, 18 Mar 2015 21:18:52 GMT
DRILL-2309: Fix reduce aggregate rule to create new aggregate calls based on input row type


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

Branch: refs/heads/master
Commit: 12a7d01791bb9ad0126f2dccf2100f09668861d1
Parents: 29fe695
Author: Mehant Baid <mehantr@gmail.com>
Authored: Tue Mar 17 19:45:38 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Tue Mar 17 23:31:34 2015 -0700

----------------------------------------------------------------------
 .../planner/logical/DrillReduceAggregatesRule.java | 14 +++++++++++---
 .../drill/exec/fn/impl/TestAggregateFunctions.java | 17 +++++++++++++++++
 .../src/test/resources/jsoninput/nullable3.json    |  3 +++
 3 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/12a7d017/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java
index 94fed87..af5c776 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillReduceAggregatesRule.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.collect.Lists;
 import org.apache.drill.exec.planner.sql.DrillSqlOperator;
 import org.eigenbase.rel.AggregateCall;
 import org.eigenbase.rel.AggregateRel;
@@ -46,7 +47,6 @@ import org.eigenbase.sql.fun.SqlAvgAggFunction;
 import org.eigenbase.sql.fun.SqlStdOperatorTable;
 import org.eigenbase.sql.fun.SqlSumAggFunction;
 import org.eigenbase.sql.fun.SqlSumEmptyIsZeroAggFunction;
-import org.eigenbase.sql.type.SqlTypeUtil;
 import org.eigenbase.util.CompositeList;
 import org.eigenbase.util.ImmutableIntList;
 import org.eigenbase.util.Util;
@@ -247,8 +247,16 @@ public class DrillReduceAggregatesRule extends RelOptRule {
       // anything else:  preserve original call
       RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
       final int nGroups = oldAggRel.getGroupCount();
-      List<RelDataType> oldArgTypes = SqlTypeUtil
-          .projectTypes(oldAggRel.getRowType(), oldCall.getArgList());
+
+      List<RelDataType> oldArgTypes = new ArrayList<>();
+      List<Integer> ordinals = oldCall.getArgList();
+
+      assert ordinals.size() <= inputExprs.size();
+
+      for (int ordinal : ordinals) {
+        oldArgTypes.add(inputExprs.get(ordinal).getType());
+      }
+
       return rexBuilder.addAggCall(
           oldCall,
           nGroups,

http://git-wip-us.apache.org/repos/asf/drill/blob/12a7d017/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
index f3c7fa5..72ad31a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestAggregateFunctions.java
@@ -168,4 +168,21 @@ public class TestAggregateFunctions extends BaseTestQuery {
         .go();
   }
 
+  @Test
+  public void testCountWithAvg() throws Exception {
+    testBuilder()
+        .sqlQuery("select count(a) col1, avg(b) col2 from cp.`jsoninput/nullable3.json`")
+        .unOrdered()
+        .baselineColumns("col1", "col2")
+        .baselineValues(2l, 3.0d)
+        .go();
+
+    testBuilder()
+        .sqlQuery("select count(a) col1, avg(a) col2 from cp.`jsoninput/nullable3.json`")
+        .unOrdered()
+        .baselineColumns("col1", "col2")
+        .baselineValues(2l, 1.0d)
+        .go();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/12a7d017/exec/java-exec/src/test/resources/jsoninput/nullable3.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/jsoninput/nullable3.json b/exec/java-exec/src/test/resources/jsoninput/nullable3.json
new file mode 100644
index 0000000..7c1f6a7
--- /dev/null
+++ b/exec/java-exec/src/test/resources/jsoninput/nullable3.json
@@ -0,0 +1,3 @@
+{"a" : 1, "b" : 3}
+{"a" : null, "b" : 3}
+{"a" : 1, "b" : null}


Mime
View raw message