Conversation
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 checks and casts against pivotColumn.dataType.asNullable instead, so a pivot value is matched to the pivot column by type, ignoring nullability.
Why are the changes needed?
pivot() on an array column fails at analysis when the array's element type is non-nullable, with an error that prints the same type on both sides:
The pivot values are collected by Spark and turned into literals by Literal.apply, which builds ArrayType(elementType), i.e. containsNull = true. Cast.canCast then rejects the cast to the column's containsNull = false type. Nullability is irrelevant here — the value is a constant that is only compared against the column — and there is no workaround, since the user does not supply the literals.
Does this PR introduce any user-facing change?
Yes. Queries that failed with PIVOT_VALUE_DATA_TYPE_MISMATCH purely because of a nullability difference now succeed. No previously working query changes its result: the cast is only loosened on nullability flags, never on base types, so genuinely mismatched values are still rejected.
How was this patch tested?
Added UT cases.
Was this patch authored or co-authored using generative AI tooling?
Yes