[SPARK-58959][SQL] Duplicate PIVOT values corrupt the aggregation buffer on the PivotFirst fast path - #58235
Draft
jiwen624 wants to merge 1 commit into
Draft
[SPARK-58959][SQL] Duplicate PIVOT values corrupt the aggregation buffer on the PivotFirst fast path#58235jiwen624 wants to merge 1 commit into
jiwen624 wants to merge 1 commit into
Conversation
…slot in PivotFirst
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.
What changes were proposed in this pull request?
PivotFirstindexed the pivot values withMap(pivotColumnValues.zipWithIndex), so values that compare as equal collapsed onto one entry holding the last of their indices whileindexSizeshrank to the distinct count, leaving the stored index pointing past the end of the buffer. Every entry now gets its own slot, shared between entries that compare as equal, andevalexpands back to one array element per entry.Why are the changes needed?
A PIVOT whose
INlist repeats a value writes outside its allocated slots in the aggregation buffer:The bounds check is an assert, so a normal build corrupts the buffer silently instead of failing. Duplicates are not limited to identical literals: (0.0D, -0.0D) and ('a', 'A') under UTF8_LCASE reach the same path. The non-optimized path already answers these queries correctly.
Does this PR introduce any user-facing change?
Yes. The optimized path now returns one column per listed value, matching the non-optimized path, instead of failing with AssertionError or silently corrupting the buffer.
How was this patch tested?
Added UT cases.
Was this patch authored or co-authored using generative AI tooling?
Yes.