Extend max_by/min_by optimization to mix of array/map/scalar type#25435
Merged
Conversation
feilong-liu
commented
Jun 25, 2025
| else { | ||
| return Result.empty(); | ||
| } | ||
| if (candidateAggregation.values().stream().noneMatch(x -> x.getArguments().get(0).getType() instanceof MapType || x.getArguments().get(0).getType() instanceof ArrayType)) { |
Contributor
Author
There was a problem hiding this comment.
Move the map/array type check here, and apply optimization as long as one of the aggregations are in map/array type
9659285 to
949e33b
Compare
jaystarshot
approved these changes
Jun 26, 2025
rschlussel
approved these changes
Jun 26, 2025
This was referenced Jul 4, 2025
This was referenced Jul 24, 2025
6 tasks
Member
|
Hi @feilong-liu , I am working on the release notes for this PR. Can you revise your release note from the user's perspective? |
Contributor
|
It's actually more than that - it's also useful when you have a lot of columns. But yeah let's start with this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This optimizer was added in #25190
The current implementation needs all max_by/min_by operates on Map type, however, I found production queries where the max_by/min_by has a mix of map and non map type.
As long as one of the min_by/max_by has a complex type, here I use map and array type, this optimization will be useful. Hence I extend it to be effective as long as one min_by/max_by is on a map or array type.
Motivation and Context
Extend existing optimizer to cover more cases
Impact
Extend existing optimizer to cover more cases
Test Plan
Unit tests
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.