drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meh...@apache.org
Subject drill git commit: DRILL-2599: Fix DrillReduceAggregatesRule to not inject additional cast for stddev
Date Mon, 30 Mar 2015 17:22:26 GMT
Repository: drill
Updated Branches:
  refs/heads/master c11fcf73f -> 96d51bded


DRILL-2599: Fix DrillReduceAggregatesRule to not inject additional cast for stddev


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

Branch: refs/heads/master
Commit: 96d51bdedbeab2f95075ca5e40cdc7b65b1c8e99
Parents: c11fcf7
Author: Mehant Baid <mehantr@gmail.com>
Authored: Fri Mar 27 00:40:46 2015 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Sat Mar 28 10:24:49 2015 -0700

----------------------------------------------------------------------
 .../planner/logical/DrillReduceAggregatesRule.java   | 15 +++++++++++++--
 .../drill/exec/fn/impl/TestAggregateFunctions.java   | 10 ++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/96d51bde/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 d5115c8..9832406 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
@@ -47,6 +47,7 @@ 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.SqlTypeName;
 import org.eigenbase.util.CompositeList;
 import org.eigenbase.util.ImmutableIntList;
 import org.eigenbase.util.Util;
@@ -352,7 +353,8 @@ public class DrillReduceAggregatesRule extends RelOptRule {
             SqlStdOperatorTable.DIVIDE,
             numeratorRef,
             denominatorRef);
-    return divideRef;
+    return rexBuilder.makeCast(
+        typeFactory.createSqlType(SqlTypeName.ANY), divideRef);
   }
 
   private RexNode reduceSum(
@@ -556,8 +558,17 @@ public class DrillReduceAggregatesRule extends RelOptRule {
           rexBuilder.makeCall(
               SqlStdOperatorTable.POWER, div, half);
     }
+
+    /*
+     * Currently calcite's strategy to infer the return type of aggregate functions
+     * is wrong because it uses the first known argument to determine output type. For
+     * instance if we are performing stddev on an integer column then it interprets the
+     * output type to be integer which is incorrect as it should be double. So based on
+     * this if we add cast after rewriting the aggregate we add an additional cast which
+     * would cause wrong results. So we simply add a cast to ANY.
+     */
     return rexBuilder.makeCast(
-        oldCall.getType(), result);
+        typeFactory.createSqlType(SqlTypeName.ANY), result);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/drill/blob/96d51bde/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 50c62e2..d4a46c1 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
@@ -194,4 +194,14 @@ public class TestAggregateFunctions extends BaseTestQuery {
         .baselineValues(578.9982683982684d)
         .go();
   }
+
+  @Test
+  public void testStddevOnKnownType() throws Exception {
+    testBuilder()
+        .sqlQuery("select stddev_samp(cast(employee_id as int)) as col from cp.`employee.json`")
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(333.56708470261117d)
+        .go();
+  }
 }


Mime
View raw message