Skip to content

Spark: Fix type mismatch in SPJ with bucket partition key - #15555

Closed
zheliu2 wants to merge 2 commits into
apache:mainfrom
zheliu2:zheliu/fix-spj-bucket-type-mismatch
Closed

Spark: Fix type mismatch in SPJ with bucket partition key#15555
zheliu2 wants to merge 2 commits into
apache:mainfrom
zheliu2:zheliu/fix-spj-bucket-type-mismatch

Conversation

@zheliu2

@zheliu2zheliu2 commented Mar 9, 2026

Copy link
Copy Markdown

Summary

Fix ClassCastException when using Storage Partition Join (SPJ) with a bucket partition key on a String column.

Problem

When a table is partitioned by bucket(N, string_column), the bucket transform produces an Integer partition value. However, StructInternalRow.getUTF8StringInternal() calls struct.get(ordinal, CharSequence.class), which assumes the value is always a CharSequence. During SPJ, Spark reads partition values through StructInternalRow, and this type mismatch causes:

IllegalArgumentException: Wrong class, expected java.lang.CharSequence, but was java.lang.Integer, for object: 1

This affects all Spark versions (3.4, 3.5, 4.0, 4.1) since SPJ was introduced in Spark 3.4.

Fix

Changed getUTF8StringInternal() to use struct.get(ordinal, Object.class) instead of struct.get(ordinal, CharSequence.class), then call value.toString(). This handles both the normal case (CharSequence from source columns) and the transform case (Integer from bucket transform).

Testing

Added testJoinsWithBucketingOnStringColumn and testJoinsWithIdentityAndBucketOnStringColumn to all 4 Spark versions for consistent coverage.

Update: Per review feedback from @huaxingao, removed redundant test and ensured consistent test coverage across all Spark versions.

Fixes#15349

When using Storage Partition Join (SPJ) with a bucket partition key on a
String column, StructInternalRow.getUTF8String could throw a
ClassCastException because it accessed the partition value using
CharSequence.class, but bucket transform produces Integer values.
Changed getUTF8StringInternal to use Object.class when accessing the
underlying struct value, avoiding the ClassCastException when the actual
partition value type differs from the source column type.
Also added test coverage for bucket transforms on String columns in SPJ
tests.
@zheliu2
zheliu2 marked this pull request as ready for review March 9, 2026 02:39
}

@TestTemplate
public void testJoinsWithBucketOnStringAndIdentityColumns() throws NoSuchTableException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testJoinsWithIdentityAndBucketOnStringColumn and testJoinsWithBucketOnStringAndIdentityColumns seem to cover the same code path. Do we need both?

Also, v4.1 only has testJoinsWithIdentityAndBucketOnStringColumn, and v3.4/v4.0 don't have any of the new tests. Should the coverage be consistent across versions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points @huaxingao! Removed the redundant testJoinsWithBucketOnStringAndIdentityColumns from v3.5, and added testJoinsWithBucketingOnStringColumn and
testJoinsWithIdentityAndBucketOnStringColumn to v3.4 and v4.0 so all four Spark versions have consistent coverage.

Address review feedback:
- Remove redundant testJoinsWithBucketOnStringAndIdentityColumns from v3.5
(covers same code path as testJoinsWithIdentityAndBucketOnStringColumn)
- Add testJoinsWithBucketingOnStringColumn and
testJoinsWithIdentityAndBucketOnStringColumn to v3.4 and v4.0
for consistent coverage across all Spark versions
@zheliu2
zheliu2 requested a review from huaxingaoMarch 9, 2026 17:24
@huaxingao

huaxingao commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

This PR appears to be generated and submitted by AI without human review. Closing for now. If you'd like to resubmit, please follow our AI contribution guidelines: https://iceberg.apache.org/contribute/#guidelines-for-ai-assisted-contributions

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPJ with Bucket Partition Key: Error: Wrong class, expected java.lang.CharSequence, but was java.lang.Integer

2 participants

@zheliu2@huaxingao