Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix equality in StructLikeMap #9236

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

aokolnychyi
Copy link
Contributor

@aokolnychyi aokolnychyi commented Dec 6, 2023

This PR fixes equality in StructLikeMap. See tests for use cases that previously failed.

@@ -146,25 +145,19 @@ public R getValue() {

@Override
public int hashCode() {
int hashCode = getKey().hashCode();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was also throwing NPE cause key could be null. Not anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, getKey().hashCode() meant we used the hash of the actual element, not the wrapper.

return false;
} else {
StructLikeEntry that = (StructLikeEntry<R>) o;
return Objects.equals(getKey(), that.getKey())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We used getKey() which unwrapped the object and we were loosing proper equality.

@@ -147,4 +149,32 @@ public void testKeysWithNulls() {

assertThat(map.remove(record3)).isEqualTo("aaa");
}

@Test
public void testEqualsAndHashCode() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we do a quick addition of a test for empty map equality? I am pretty sure that is fine but just to be complete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll add that.

Copy link
Member

@RussellSpitzer RussellSpitzer left a comment

Choose a reason for hiding this comment

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

One more nit about empty map comparison tests but this looks good to me

@aokolnychyi aokolnychyi merged commit e276753 into apache:main Dec 6, 2023
46 checks passed
@aokolnychyi
Copy link
Contributor Author

Thanks, @RussellSpitzer!

lisirrx pushed a commit to lisirrx/iceberg that referenced this pull request Jan 4, 2024
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants