Spark: Fix type mismatch in SPJ with bucket partition key on string column#16424
Open
ammarchalifah wants to merge 1 commit into
Open
Spark: Fix type mismatch in SPJ with bucket partition key on string column#16424ammarchalifah wants to merge 1 commit into
ammarchalifah wants to merge 1 commit into
Conversation
Author
|
This PR is a re-implementation of this closed PR: #15555 I was the reporter that filed the bug report, and really needed this bug to be fixed. |
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.
Problem
When a table is partitioned by
bucket(N, string_column), the bucket transform produces anIntegerpartition value. During Storage Partitioned Joins (SPJ), Spark reads partition values throughStructInternalRow, which callsstruct.get(ordinal, CharSequence.class)ingetUTF8StringInternal(). This assumes the value is always aCharSequence, causing aClassCastException:This affects any SPJ query (e.g.
MERGE INTOorJOIN) on tables partitionedwith
bucket(N, string_column).Fix
Changed
getUTF8StringInternal()to usestruct.get(ordinal, Object.class)instead ofstruct.get(ordinal, CharSequence.class), then callvalue.toString(). This follows the same pattern already used bygetBinaryInternal()in the same class, which usesObject.classto handle multiple possible runtime types.The fix is applied to all Spark versions: 3.4, 3.5, 4.0, and 4.1.
Testing
testJoinsWithBucketingOnStringColumnusing the existingcheckJoinhelper to cover bucket-only partitioning on string columns.testJoinsWithIdentityAndBucketOnStringColumnas a targeted regression test for the exact scenario from the issue: identity + bucket partitioning on a string column with an SPJ join.Both tests are added consistently across all 4 Spark versions.
Notes
AI tools were used to assist with drafting this change. I have reviewed and
validated the logic, tests, and code style end-to-end.
Closes #15349