Skip to content

Core: Fix StructLikeWrapper.equals exception with comparator failure#15945

Merged
huaxingao merged 1 commit intoapache:mainfrom
ebyhr:ebi/struct-wrapper
Apr 16, 2026
Merged

Core: Fix StructLikeWrapper.equals exception with comparator failure#15945
huaxingao merged 1 commit intoapache:mainfrom
ebyhr:ebi/struct-wrapper

Conversation

@ebyhr
Copy link
Copy Markdown
Member

@ebyhr ebyhr commented Apr 12, 2026

StructLikeWrapper.equals threw an exception when the comparator threw an exception. This PR wraps the comparator.compare call in a try-catch so that type mismatches return false instead of propagating the exception.

The newly added test fails if we revert the StructLikeWrapper.equals change:

Wrong class, expected java.lang.Integer, but was java.lang.String, for object: test
java.lang.IllegalArgumentException: Wrong class, expected java.lang.Integer, but was java.lang.String, for object: test
	at org.apache.iceberg.PartitionData.get(PartitionData.java:126)
	at org.apache.iceberg.types.Comparators$StructLikeComparator.compare(Comparators.java:122)
	at org.apache.iceberg.types.Comparators$StructLikeComparator.compare(Comparators.java:95)
	at org.apache.iceberg.util.StructLikeWrapper.equals(StructLikeWrapper.java:91)
	at org.assertj.core.internal.StandardComparisonStrategy.areEqual(StandardComparisonStrategy.java:111)
	at org.assertj.core.internal.Objects.areEqual(Objects.java:231)
	at org.assertj.core.internal.Objects.assertNotEqual(Objects.java:227)
	at org.assertj.core.api.AbstractAssert.isNotEqualTo(AbstractAssert.java:394)
	at org.apache.iceberg.util.TestStructLikeWrapper.equalsTypeAndDataMismatch(TestStructLikeWrapper.java:45)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

@github-actions github-actions bot added the core label Apr 12, 2026
@ebyhr ebyhr changed the title Core: Fix StructLikeWrapper.equals exception with mismatched partition types Core: Fix StructLikeWrapper.equals exception with comparator failure Apr 12, 2026
return comparator.compare(this.struct, that.struct) == 0;
try {
return comparator.compare(this.struct, that.struct) == 0;
} catch (Throwable e) {
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.

Throwable is a bit too broad, Can you just catch the correct exception (which is IllegalArgumentException?) At worst, catch only Exception

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.

+1, worst case we can just have RTE catched

Copy link
Copy Markdown
Member Author

@ebyhr ebyhr Apr 12, 2026

Choose a reason for hiding this comment

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

I'm wondering if catching only IllegalArgumentException is really the right approach. Because the error originates from StructLike#get, the behavior depends on each implementation and the specific exception type is not guaranteed. I've changed this to catch RuntimeException instead.

@ebyhr ebyhr force-pushed the ebi/struct-wrapper branch from fac9d88 to 5dc2870 Compare April 12, 2026 22:20
Comment thread core/src/main/java/org/apache/iceberg/util/StructLikeWrapper.java
@huaxingao huaxingao merged commit 0babf7d into apache:main Apr 16, 2026
36 checks passed
@huaxingao
Copy link
Copy Markdown
Contributor

Thanks @ebyhr for the PR! Thanks @anoopj @krvikash @nastra @singhpk234 for the review!

@ebyhr ebyhr deleted the ebi/struct-wrapper branch April 16, 2026 03:23
Sign up for free to 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.

6 participants