From 37176936330d4241947ea2de48f13441e6b2933e Mon Sep 17 00:00:00 2001 From: Maytas Monsereenusorn Date: Thu, 3 Feb 2022 12:01:13 -0800 Subject: [PATCH] Fix java.lang.ClassCastException error when using useApproximateCountDistinct false for aggregation query (#12216) * add imply * add test * add unit test * add test --- .../sql/calcite/rel/PartialDruidQuery.java | 3 +- .../druid/sql/calcite/CalciteQueryTest.java | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java index e88616a3d84..15bcd5d4bda 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java @@ -188,7 +188,8 @@ public class PartialDruidQuery relBuilder.push(selectProject.getInput()); relBuilder.project( newProjectRexNodes, - newSelectProject.getRowType().getFieldNames() + newSelectProject.getRowType().getFieldNames(), + true ); theProject = (Project) relBuilder.build(); } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 4c63b2142b4..41179921969 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -8173,6 +8173,98 @@ public class CalciteQueryTest extends BaseCalciteQueryTest ); } + @Test + public void testQueryWithSelectProjectAndIdentityProjectDoesNotRename() throws Exception + { + cannotVectorize(); + requireMergeBuffers(3); + testQuery( + PLANNER_CONFIG_NO_HLL.withOverrides(ImmutableMap.of( + PlannerConfig.CTX_KEY_USE_GROUPING_SET_FOR_EXACT_DISTINCT, + "true" + )), + "SELECT\n" + + "(SUM(CASE WHEN (TIMESTAMP '2000-01-04 17:00:00'<=__time AND __time