This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 7374e1c55b [#8012] fix: include namespace in TableEntity hashCode
(#8019)
7374e1c55b is described below
commit 7374e1c55b6a7faee0d108a34b5b1c8b2b1ec97c
Author: Joonseo Lee <[email protected]>
AuthorDate: Tue Aug 12 20:52:05 2025 +0900
[#8012] fix: include namespace in TableEntity hashCode (#8019)
### What changes were proposed in this pull request?
This PR updates the TableEntity.hashCode() implementation to include the
namespace field in the hash calculation.
It also updates related test cases to validate the change and applies
Spotless formatting to comply with the project code style.
### Why are the changes needed?
The current hashCode() implementation does not include the namespace
field, causing objects with different namespaces to have identical hash
values.
This could lead to incorrect behavior when TableEntity objects are used
in hash-based collections (e.g., HashSet, HashMap).
By including the namespace, equality and hash consistency are ensured.
Fix: #8012
### Does this PR introduce _any_ user-facing change?
No. This change only affects internal equality/hash logic of TableEntity
and does not modify any user-facing API or property keys.
### How was this patch tested?
Updated existing unit tests in TestEntity.java
---
.../org/apache/gravitino/meta/TableEntity.java | 2 +-
.../java/org/apache/gravitino/meta/TestEntity.java | 53 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
b/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
index f661cd049a..9d15be7df6 100644
--- a/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
+++ b/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
@@ -141,7 +141,7 @@ public class TableEntity implements Entity, Auditable,
HasIdentifier {
@Override
public int hashCode() {
- return Objects.hashCode(id, name, auditInfo, columns);
+ return Objects.hashCode(id, name, auditInfo, columns, namespace);
}
public static class Builder {
diff --git a/core/src/test/java/org/apache/gravitino/meta/TestEntity.java
b/core/src/test/java/org/apache/gravitino/meta/TestEntity.java
index c1509996ed..8bff5ce966 100644
--- a/core/src/test/java/org/apache/gravitino/meta/TestEntity.java
+++ b/core/src/test/java/org/apache/gravitino/meta/TestEntity.java
@@ -23,9 +23,11 @@ import static
org.apache.gravitino.file.Fileset.LOCATION_NAME_UNKNOWN;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.time.Instant;
+import java.util.Collections;
import java.util.Map;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.Field;
+import org.apache.gravitino.Namespace;
import org.apache.gravitino.authorization.Privileges;
import org.apache.gravitino.authorization.SecurableObjects;
import org.apache.gravitino.file.Fileset;
@@ -339,4 +341,55 @@ public class TestEntity {
Assertions.assertNull(tag2.comment());
Assertions.assertNull(tag2.properties());
}
+
+ @Test
+ public void testHashCodeIncludesNamespace() {
+ AuditInfo audit =
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build();
+
+ TableEntity table1 =
+ TableEntity.builder()
+ .withId(1L)
+ .withName("t")
+ .withNamespace(Namespace.of("catalog", "schema1"))
+ .withColumns(Collections.emptyList())
+ .withAuditInfo(audit)
+ .build();
+
+ TableEntity table2 =
+ TableEntity.builder()
+ .withId(1L)
+ .withName("t")
+ .withNamespace(Namespace.of("catalog", "schema2"))
+ .withColumns(Collections.emptyList())
+ .withAuditInfo(audit)
+ .build();
+
+ Assertions.assertNotEquals(
+ table1.hashCode(), table2.hashCode(), "hashCode should include
namespace");
+ }
+
+ @Test
+ public void testHashCodeWithDifferentNamespaceHavingSameValues() {
+ AuditInfo audit =
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build();
+
+ TableEntity table1 =
+ TableEntity.builder()
+ .withId(2L)
+ .withName("t")
+ .withNamespace(Namespace.of("catalog", "schema1"))
+ .withColumns(Collections.emptyList())
+ .withAuditInfo(audit)
+ .build();
+
+ TableEntity table2 =
+ TableEntity.builder()
+ .withId(2L)
+ .withName("t")
+ .withNamespace(Namespace.of("catalog", "schema1"))
+ .withColumns(Collections.emptyList())
+ .withAuditInfo(audit)
+ .build();
+
+ Assertions.assertEquals(table1.hashCode(), table2.hashCode(), "hashCode
should be the same");
+ }
}