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

mihaibudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new aecb0c0e53 [CALCITE-7938] AggregateRemoveRule can cause failed 
planning because of collation mismatch
aecb0c0e53 is described below

commit aecb0c0e53b6ff7ddddeed212bbc4bda6d468bcc
Author: npaincomplet <[email protected]>
AuthorDate: Sun Nov 15 23:10:38 2026 +0100

    [CALCITE-7938] AggregateRemoveRule can cause failed planning because of 
collation mismatch
---
 .../calcite/rel/rules/AggregateRemoveRule.java       |  4 +++-
 core/src/test/resources/sql/hep.iq                   | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java 
b/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
index c4d406af21..aabfde544d 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
@@ -160,7 +160,9 @@ public static boolean canFlattenStatic(AggregateCall 
aggregateCall) {
       relBuilder.project(relBuilder.fields(aggregate.getGroupSet()));
     }
     call.getPlanner().prune(aggregate);
-    call.transformTo(relBuilder.build());
+    final RelNode replacement = relBuilder.build().stripped();
+    call.transformTo(
+        replacement.copy(aggregate.getTraitSet(), replacement.getInputs()));
   }
 
   /** Rule configuration. */
diff --git a/core/src/test/resources/sql/hep.iq 
b/core/src/test/resources/sql/hep.iq
index 3498fdea19..87d77b3bd2 100644
--- a/core/src/test/resources/sql/hep.iq
+++ b/core/src/test/resources/sql/hep.iq
@@ -411,4 +411,24 @@ PLAN VARCHAR NOT NULL
 !type
 !set hep-rules original
 
+# [CALCITE-7938] AggregateRemoveRule can cause failed planning because of 
collation mismatch
+!set hep-rules "
++CoreRules.AGGREGATE_PROJECT_MERGE,
++CoreRules.AGGREGATE_REMOVE"
+
+select count(*) as s
+from (values (true, 1), (true, 2)) as t(col1, col2)
+where col1
+group by col2;
++---+
+| S |
++---+
+| 1 |
+| 1 |
++---+
+(2 rows)
+
+!ok
+!set hep-rules original
+
 # End hep.iq

Reply via email to