NobiGo commented on code in PR #4201:
URL: https://github.com/apache/calcite/pull/4201#discussion_r2013894178


##########
core/src/main/java/org/apache/calcite/rel/rules/ProjectAggregateMergeRule.java:
##########
@@ -154,9 +156,22 @@ && kindCount(project.getProjects(), SqlKind.CASE) == 0) {
     builder.push(aggregate.getInput());
     builder.aggregate(
         builder.groupKey(aggregate.getGroupSet(), aggregate.groupSets), 
aggCallList);
-    builder.project(
-        RexPermuteInputsShuttle.of(mapping).visitList(projects2),
-            project.getRowType().getFieldNames());
+    // If the output type of Aggregate does not match the input type required 
by original Project,
+    // CAST needs to be added
+    List<RexNode> rexInputRefs = 
RexPermuteInputsShuttle.of(mapping).visitList(projects2);

Review Comment:
   I re-examined the root cause of this ISSUE. It lies in the fact that after 
adding SUM0(), the referenced type is indeed CAST type, which should be the 
return type of SUM0(). After performing type conversion in the final Project, 
it becomes much simpler. Therefore, I made corresponding changes. Please review 
again.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to