[SPARK-55483] Fix NPE in PivotFirst when pivot column is a non-atomic type with null values #54267
+36
−1
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?
Added a null-safe
findPivotIndexlookup method that returns-1for null keys on theTreeMappath, sincenullcan never be a validTreeMapkey. TheHashMappath (atomic types) is unchanged, as it handlesnullkeys safely and allows null as a valid pivot value.Why are the changes needed?
When a
PIVOTquery uses a non-atomic pivot column (struct, array),PivotFirststores pivot values in aTreeMapwith a comparison-based ordering. If the pivot column contains null values (e.g., from a GROUP BY null group), theTreeMap.getOrElselookup callscompare(null, existingKey), which throws aNullPointerException.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added unit test in
DataFramePivotSuite.scala.Was this patch authored or co-authored using generative AI tooling?
No.
Please refer to the ASF Generative Tooling Guidance for details.
-->