You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by lu...@apache.org on 2021/07/03 02:51:34 UTC

[drill] branch master updated: DRILL-7931: Fix rowtype mismatch in DrillReduceAggregatesRule (#2259)

This is an automated email from the ASF dual-hosted git repository.

luoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git


The following commit(s) were added to refs/heads/master by this push:
     new 15da887  DRILL-7931: Fix rowtype mismatch in DrillReduceAggregatesRule (#2259)
15da887 is described below

commit 15da88779eead5af49b04b3c9e9953f72a5d1d35
Author: feiteng <32...@qq.com>
AuthorDate: Mon Jun 14 18:25:59 2021 +0800

    DRILL-7931: Fix rowtype mismatch in DrillReduceAggregatesRule (#2259)
---
 .../exec/planner/logical/DrillReduceAggregatesRule.java    |  9 ++++++++-
 .../apache/drill/exec/fn/impl/TestAggregateFunctions.java  | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

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 43574aa..0097665 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
@@ -298,7 +298,14 @@ public class DrillReduceAggregatesRule extends RelOptRule {
       for (int ordinal : ordinals) {
         oldArgTypes.add(inputExprs.get(ordinal).getType());
       }
-
+      //to solve AggregateCall returns true with equals method but has
+      // different RelDataTypes
+      if (aggCallMapping.containsKey(oldCall) && !aggCallMapping.get(oldCall)
+        .getType().equals(oldCall.getType())) {
+        int index = newCalls.size() + nGroups;
+        newCalls.add(oldCall);
+        return rexBuilder.makeInputRef(oldCall.getType(), index);
+      }
       return rexBuilder.addAggCall(
           oldCall,
           nGroups,
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 61e87f7..182c983 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
@@ -1239,4 +1239,18 @@ public class TestAggregateFunctions extends ClusterTest {
       client.resetSession(PlannerSettings.STREAMAGG.getOptionName());
     }
   }
+
+  @Test //DRILL-7931
+  public void testRowTypeMissMatch() throws Exception {
+    testBuilder()
+      .sqlQuery("select col1, stddev(col2) as g1, SUM(col2) as g2 FROM " +
+        "(values ('UA', 3), ('USA', 2), ('UA', 3), ('USA', 5), ('USA', 1), " +
+        "('UA', 9)) t(col1, col2) GROUP BY col1 order by col1")
+      .unOrdered()
+      .approximateEquality(0.000001)
+      .baselineColumns("col1", "g1", "g2")
+      .baselineValues("UA", 3.4641016151377544, 15L)
+      .baselineValues("USA", 2.0816659994661326, 8L)
+      .go();
+  }
 }