[SPARK-59678][SQL] Fix pivot failing on array and struct columns with non-nullable nested fields - #58934
Open
jiwen624 wants to merge 2 commits into
Open
[SPARK-59678][SQL] Fix pivot failing on array and struct columns with non-nullable nested fields#58934jiwen624 wants to merge 2 commits into
jiwen624 wants to merge 2 commits into
Conversation
jiwen624
force-pushed
the
SPARK-59678
branch
from
September 22, 2026 00:28
e6919a7 to
fa26201
Compare
jiwen624
force-pushed
the
SPARK-59678
branch
from
September 23, 2026 04:38
7dd6d14 to
8b0f198
Compare
jiwen624
force-pushed
the
SPARK-59678
branch
from
September 23, 2026 06:06
8b0f198 to
0ef0869
Compare
jiwen624
marked this pull request as ready for review
September 24, 2026 21:13
Contributor
Author
|
Hi @uros-b @cloud-fan since you've reviewed pivot-related fixes recently, could you let me know what do you think about this fix when you get a chance? Thanks! 🙇 |
This branch has not been deployed
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?
PivotTransformer checks and casts each pivot value against pivotColumn.dataType. This PR ignores nullability in that match: the check strips nullability from the value's type before comparing it with the pivot column's type, and values are evaluated against pivotColumn.dataType.asNullable. The If filters for non-PivotFirst aggregates fall back to asNullable only when the exact type can't be cast to, so existing plans are unchanged.
Why are the changes needed?
A pivot value fails analysis when its type allows nulls in a nested position where the pivot column's type does not, with an error that prints the same type on both sides:
The same happens with explicit DataFrame values, e.g. pivot($"a", Seq(Array(1.0d))) on a non-nullable-element array. Nullability is irrelevant here, as the value is a constant only compared against the column. (pivot() without values is covered by SPARK-59684.)
Note that for a non-nullable nested column, a value that can't be cast now fails with CAST_INVALID_INPUT (ANSI) or becomes null (non-ANSI), the same as the scalar and nullable cases, instead of PIVOT_VALUE_DATA_TYPE_MISMATCH.
Does this PR introduce any user-facing change?
Yes. Queries that failed with PIVOT_VALUE_DATA_TYPE_MISMATCH only because the value's type allows nulls in a nested position where the pivot column's type does not now run. Queries that already passed analysis are unaffected, and other rejected values keep the same error.
How was this patch tested?
Added UT cases.
Was this patch authored or co-authored using generative AI tooling?
Yes