Skip to content

[CALCITE-7162] AggregateMergeRule type mismatch on MIN/MAX - #4527

Merged
gianm merged 1 commit into
apache:mainfrom
gianm:CALCITE-7162
Sep 12, 2025
Merged

[CALCITE-7162] AggregateMergeRule type mismatch on MIN/MAX#4527
gianm merged 1 commit into
apache:mainfrom
gianm:CALCITE-7162

Conversation

@gianm

@gianm gianm commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

Fixes CALCITE-7162 by taking the type from the top aggregator rather than the bottom aggregator when merging. A similar fix was made to AbstractSumSplitter in CALCITE-6557.

This patch also updates CountSplitter with a similar change— just in case— even though I'm not sure if that is necessary to fix any actual bug. I believe that in general using the top aggregator type is the correct thing to do, since the merged aggregator is meant to stand in for the top aggregator.

@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2025

Copy link
Copy Markdown

@xiedeyantu

Copy link
Copy Markdown
Member

If you have also updated the CountSplitter, I hope you can add a relevant test case.

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, but it would be great if @julianhyde could confirm.

@julianhyde

Copy link
Copy Markdown
Contributor

Can we have a generic solution that works for all aggregate functions?

@gianm

gianm commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

Can we have a generic solution that works for all aggregate functions?

In this patch I updated all existing SqlSplittableAggFunction implementations. If there is something more generic you had in mind, please let me know.

If you have also updated the CountSplitter, I hope you can add a relevant test case.

I tried for a bit to find a case where the current CountSplitter breaks, but couldn't, so I didn't add a test case. There are already a lot of test cases for COUNT splitting. It's possible the current code is "fine" because COUNT splits into COUNT and SUM0, which won't have different nullability. I updated the CountSplitter anyway just to keep all the Splitter implementations harmonious.

@gianm

gianm commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

Thanks all for having a look. I will commit it since I believe I've addressed the comments as best as they can be.

@gianm
gianm merged commit d0e0d0e into apache:main Sep 12, 2025
20 checks passed
@gianm
gianm deleted the CALCITE-7162 branch September 12, 2025 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants