Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8012] fix: include namespace in TableEntity hashCode (#8019)

Joonseo Lee7374e1c55b6a
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");
+ }
}