World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#3627] refactor(API): Make NameIdentifier more generic for better client use (#3696)
Shaofeng Shif973dbb62a32
diff --git a/api/src/main/java/com/datastrato/gravitino/NameIdentifier.java b/api/src/main/java/com/datastrato/gravitino/NameIdentifier.javaindex b3c40bbdbc..5f9cd1398f 100644--- a/api/src/main/java/com/datastrato/gravitino/NameIdentifier.java+++ b/api/src/main/java/com/datastrato/gravitino/NameIdentifier.java@@ -50,152 +50,6 @@ public class NameIdentifier {return new NameIdentifier(namespace, name);}- /**- * Create the metalake {@link NameIdentifier} with the given name.- *- * @param metalake The metalake name- * @return The created metalake {@link NameIdentifier}- */- public static NameIdentifier ofMetalake(String metalake) {- return NameIdentifier.of(metalake);- }-- /**- * Create the catalog {@link NameIdentifier} with the given metalake and catalog name.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @return The created catalog {@link NameIdentifier}- */- public static NameIdentifier ofCatalog(String metalake, String catalog) {- return NameIdentifier.of(metalake, catalog);- }-- /**- * Create the schema {@link NameIdentifier} with the given metalake, catalog and schema name.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @return The created schema {@link NameIdentifier}- */- public static NameIdentifier ofSchema(String metalake, String catalog, String schema) {- return NameIdentifier.of(metalake, catalog, schema);- }-- /**- * Create the table {@link NameIdentifier} with the given metalake, catalog, schema and table- * name.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @param table The table name- * @return The created table {@link NameIdentifier}- */- public static NameIdentifier ofTable(- String metalake, String catalog, String schema, String table) {- return NameIdentifier.of(metalake, catalog, schema, table);- }-- /**- * Create the fileset {@link NameIdentifier} with the given metalake, catalog, schema and fileset- * name.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @param fileset The fileset name- * @return The created fileset {@link NameIdentifier}- */- public static NameIdentifier ofFileset(- String metalake, String catalog, String schema, String fileset) {- return NameIdentifier.of(metalake, catalog, schema, fileset);- }-- /**- * Create the topic {@link NameIdentifier} with the given metalake, catalog, schema and topic- * name.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @param topic The topic name- * @return The created topic {@link NameIdentifier}- */- public static NameIdentifier ofTopic(- String metalake, String catalog, String schema, String topic) {- return NameIdentifier.of(metalake, catalog, schema, topic);- }-- /**- * Check the given {@link NameIdentifier} is a metalake identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The metalake {@link NameIdentifier} to check.- */- public static void checkMetalake(NameIdentifier ident) {- // We don't have to check the name field of NameIdentifier, it's already checked when- // creating NameIdentifier object.- check(ident != null, "Metalake identifier must not be null");- Namespace.checkMetalake(ident.namespace);- }-- /**- * Check the given {@link NameIdentifier} is a catalog identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The catalog {@link NameIdentifier} to check.- */- public static void checkCatalog(NameIdentifier ident) {- check(ident != null, "Catalog identifier must not be null");- Namespace.checkCatalog(ident.namespace);- }-- /**- * Check the given {@link NameIdentifier} is a schema identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The schema {@link NameIdentifier} to check.- */- public static void checkSchema(NameIdentifier ident) {- check(ident != null, "Schema identifier must not be null");- Namespace.checkSchema(ident.namespace);- }-- /**- * Check the given {@link NameIdentifier} is a table identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The table {@link NameIdentifier} to check.- */- public static void checkTable(NameIdentifier ident) {- check(ident != null, "Table identifier must not be null");- Namespace.checkTable(ident.namespace);- }-- /**- * Check the given {@link NameIdentifier} is a fileset identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The fileset {@link NameIdentifier} to check.- */- public static void checkFileset(NameIdentifier ident) {- check(ident != null, "Fileset identifier must not be null");- Namespace.checkFileset(ident.namespace);- }-- /**- * Check the given {@link NameIdentifier} is a topic identifier. Throw an {@link- * IllegalNameIdentifierException} if it's not.- *- * @param ident The topic {@link NameIdentifier} to check.- */- public static void checkTopic(NameIdentifier ident) {- check(ident != null, "Topic identifier must not be null");- Namespace.checkTopic(ident.namespace);- }-/*** Create a {@link NameIdentifier} from the given identifier string.*diff --git a/api/src/main/java/com/datastrato/gravitino/Namespace.java b/api/src/main/java/com/datastrato/gravitino/Namespace.javaindex ae469ff3d4..f75081ce46 100644--- a/api/src/main/java/com/datastrato/gravitino/Namespace.java+++ b/api/src/main/java/com/datastrato/gravitino/Namespace.java@@ -51,150 +51,6 @@ public class Namespace {return new Namespace(levels);}- /**- * Create a namespace for metalake.- *- * @return A namespace for metalake- */- public static Namespace ofMetalake() {- return empty();- }-- /**- * Create a namespace for catalog.- *- * @param metalake The metalake name- * @return A namespace for catalog- */- public static Namespace ofCatalog(String metalake) {- return of(metalake);- }-- /**- * Create a namespace for schema.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @return A namespace for schema- */- public static Namespace ofSchema(String metalake, String catalog) {- return of(metalake, catalog);- }-- /**- * Create a namespace for table.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @return A namespace for table- */- public static Namespace ofTable(String metalake, String catalog, String schema) {- return of(metalake, catalog, schema);- }-- /**- * Create a namespace for fileset.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @return A namespace for fileset- */- public static Namespace ofFileset(String metalake, String catalog, String schema) {- return of(metalake, catalog, schema);- }-- /**- * Create a namespace for topic.- *- * @param metalake The metalake name- * @param catalog The catalog name- * @param schema The schema name- * @return A namespace for topic- */- public static Namespace ofTopic(String metalake, String catalog, String schema) {- return of(metalake, catalog, schema);- }-- /**- * Check if the given metalake namespace is legal, throw an {@link IllegalNamespaceException} if- * it's illegal.- *- * @param namespace The metalake namespace- */- public static void checkMetalake(Namespace namespace) {- check(- namespace != null && namespace.isEmpty(),- "Metalake namespace must be non-null and empty, the input namespace is %s",- namespace);- }-- /**- * Check if the given catalog namespace is legal, throw an {@link IllegalNamespaceException} if- * it's illegal.- *- * @param namespace The catalog namespace- */- public static void checkCatalog(Namespace namespace) {- check(- namespace != null && namespace.length() == 1,- "Catalog namespace must be non-null and have 1 level, the input namespace is %s",- namespace);- }-- /**- * Check if the given schema namespace is legal, throw an {@link IllegalNamespaceException} if- * it's illegal.- *- * @param namespace The schema namespace- */- public static void checkSchema(Namespace namespace) {- check(- namespace != null && namespace.length() == 2,- "Schema namespace must be non-null and have 2 levels, the input namespace is %s",- namespace);- }-- /**- * Check if the given table namespace is legal, throw an {@link IllegalNamespaceException} if it's- * illegal.- *- * @param namespace The table namespace- */- public static void checkTable(Namespace namespace) {- check(- namespace != null && namespace.length() == 3,- "Table namespace must be non-null and have 3 levels, the input namespace is %s",- namespace);- }-- /**- * Check if the given fileset namespace is legal, throw an {@link IllegalNamespaceException} if- * it's illegal.- *- * @param namespace The fileset namespace- */- public static void checkFileset(Namespace namespace) {- check(- namespace != null && namespace.length() == 3,- "Fileset namespace must be non-null and have 3 levels, the input namespace is %s",- namespace);- }-- /**- * Check if the given topic namespace is legal, throw an {@link IllegalNamespaceException} if it's- * illegal.- *- * @param namespace The topic namespace- */- public static void checkTopic(Namespace namespace) {- check(- namespace != null && namespace.length() == 3,- "Topic namespace must be non-null and have 3 levels, the input namespace is %s",- namespace);- }-private Namespace(String[] levels) {this.levels = levels;}diff --git a/api/src/test/java/com/datastrato/gravitino/TestNameIdentifier.java b/api/src/test/java/com/datastrato/gravitino/TestNameIdentifier.javaindex aefb79bf8e..3d91ad004f 100644--- a/api/src/test/java/com/datastrato/gravitino/TestNameIdentifier.java+++ b/api/src/test/java/com/datastrato/gravitino/TestNameIdentifier.java@@ -10,8 +10,6 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;import static org.junit.jupiter.api.Assertions.assertThrows;import static org.junit.jupiter.api.Assertions.assertTrue;-import com.datastrato.gravitino.exceptions.IllegalNameIdentifierException;-import com.datastrato.gravitino.exceptions.IllegalNamespaceException;import org.junit.jupiter.api.Test;public class TestNameIdentifier {@@ -92,34 +90,4 @@ public class TestNameIdentifier {assertEquals("a", id1.toString());assertEquals("a.b.c", id2.toString());}-- @Test- public void testCheckNameIdentifier() {- NameIdentifier abc = NameIdentifier.of("a", "b", "c");- NameIdentifier abcd = NameIdentifier.of("a", "b", "c", "d");-- // Test metalake- assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifier.checkMetalake(null));- Throwable excep =- assertThrows(IllegalNamespaceException.class, () -> NameIdentifier.checkMetalake(abc));- assertTrue(excep.getMessage().contains("Metalake namespace must be non-null and empty"));-- // test catalog- assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifier.checkCatalog(null));- Throwable excep1 =- assertThrows(IllegalNamespaceException.class, () -> NameIdentifier.checkCatalog(abc));- assertTrue(excep1.getMessage().contains("Catalog namespace must be non-null and have 1 level"));-- // test schema- assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifier.checkSchema(null));- Throwable excep2 =- assertThrows(IllegalNamespaceException.class, () -> NameIdentifier.checkSchema(abcd));- assertTrue(excep2.getMessage().contains("Schema namespace must be non-null and have 2 levels"));-- // test table- assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifier.checkTable(null));- Throwable excep3 =- assertThrows(IllegalNamespaceException.class, () -> NameIdentifier.checkTable(abc));- assertTrue(excep3.getMessage().contains("Table namespace must be non-null and have 3 levels"));- }}diff --git a/api/src/test/java/com/datastrato/gravitino/TestNamespace.java b/api/src/test/java/com/datastrato/gravitino/TestNamespace.javaindex 8b12b75c22..75b09a0717 100644--- a/api/src/test/java/com/datastrato/gravitino/TestNamespace.java+++ b/api/src/test/java/com/datastrato/gravitino/TestNamespace.java@@ -4,7 +4,6 @@*/package com.datastrato.gravitino;-import com.datastrato.gravitino.exceptions.IllegalNamespaceException;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.Test;@@ -33,39 +32,4 @@ public class TestNamespace {Assertions.assertThrows(IllegalArgumentException.class, () -> Namespace.of("a", null, "c"));Assertions.assertThrows(IllegalArgumentException.class, () -> Namespace.of("a", "", "c"));}-- @Test- public void testCheckNamespace() {- Namespace a = Namespace.of("a");- Namespace ab = Namespace.of("a", "b");- Namespace abcd = Namespace.of("a", "b", "c", "d");-- // Test metalake- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkMetalake(null));- Throwable excep =- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkMetalake(ab));- Assertions.assertTrue(- excep.getMessage().contains("Metalake namespace must be non-null and empty"));-- // Test catalog- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkCatalog(null));- Throwable excep1 =- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkCatalog(ab));- Assertions.assertTrue(- excep1.getMessage().contains("Catalog namespace must be non-null and have 1 level"));-- // Test schema- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkSchema(null));- Throwable excep2 =- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkSchema(a));- Assertions.assertTrue(- excep2.getMessage().contains("Schema namespace must be non-null and have 2 levels"));-- // Test table- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkTable(null));- Throwable excep3 =- Assertions.assertThrows(IllegalNamespaceException.class, () -> Namespace.checkTable(abcd));- Assertions.assertTrue(- excep3.getMessage().contains("Table namespace must be non-null and have 3 levels"));- }}diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.javaindex c4d624050c..67b4650591 100644--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java@@ -35,6 +35,7 @@ import com.datastrato.gravitino.file.Fileset;import com.datastrato.gravitino.file.FilesetChange;import com.datastrato.gravitino.storage.IdGenerator;import com.datastrato.gravitino.storage.RandomIdGenerator;+import com.datastrato.gravitino.utils.NameIdentifierUtil;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;import java.io.IOException;@@ -221,13 +222,13 @@ public class TestHadoopCatalogOperations {String comment = "comment15";String catalogPath = TEST_ROOT_PATH + "/" + "catalog15";Schema schema = createSchema(name, comment, catalogPath, null);- NameIdentifier schema16 = NameIdentifier.ofSchema("m1", "c1", "schema16");+ NameIdentifier schema16 = NameIdentifierUtil.ofSchema("m1", "c1", "schema16");Assertions.assertEquals(name, schema.name());try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(Maps.newHashMap(), null, HADOOP_PROPERTIES_METADATA);- Schema schema1 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Schema schema1 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));Assertions.assertEquals(name, schema1.name());Assertions.assertEquals(comment, schema1.comment());@@ -254,8 +255,8 @@ public class TestHadoopCatalogOperations {Set<NameIdentifier> idents =Arrays.stream(ops.listSchemas(Namespace.of("m1", "c1"))).collect(Collectors.toSet());Assertions.assertTrue(idents.size() >= 2);- Assertions.assertTrue(idents.contains(NameIdentifier.ofSchema("m1", "c1", name)));- Assertions.assertTrue(idents.contains(NameIdentifier.ofSchema("m1", "c1", name1)));+ Assertions.assertTrue(idents.contains(NameIdentifierUtil.ofSchema("m1", "c1", name)));+ Assertions.assertTrue(idents.contains(NameIdentifierUtil.ofSchema("m1", "c1", name1)));}}@@ -269,7 +270,7 @@ public class TestHadoopCatalogOperations {try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(Maps.newHashMap(), null, HADOOP_PROPERTIES_METADATA);- Schema schema1 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Schema schema1 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));Assertions.assertEquals(name, schema1.name());Assertions.assertEquals(comment, schema1.comment());@@ -279,26 +280,27 @@ public class TestHadoopCatalogOperations {String newKey = "k1";String newValue = "v1";SchemaChange setProperty = SchemaChange.setProperty(newKey, newValue);- Schema schema2 = ops.alterSchema(NameIdentifier.ofSchema("m1", "c1", name), setProperty);+ Schema schema2 = ops.alterSchema(NameIdentifierUtil.ofSchema("m1", "c1", name), setProperty);Assertions.assertEquals(name, schema2.name());Assertions.assertEquals(comment, schema2.comment());Map<String, String> props2 = schema2.properties();Assertions.assertTrue(props2.containsKey(newKey));Assertions.assertEquals(newValue, props2.get(newKey));- Schema schema3 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Schema schema3 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));Map<String, String> props3 = schema3.properties();Assertions.assertTrue(props3.containsKey(newKey));Assertions.assertEquals(newValue, props3.get(newKey));SchemaChange removeProperty = SchemaChange.removeProperty(newKey);- Schema schema4 = ops.alterSchema(NameIdentifier.ofSchema("m1", "c1", name), removeProperty);+ Schema schema4 =+ ops.alterSchema(NameIdentifierUtil.ofSchema("m1", "c1", name), removeProperty);Assertions.assertEquals(name, schema4.name());Assertions.assertEquals(comment, schema4.comment());Map<String, String> props4 = schema4.properties();Assertions.assertFalse(props4.containsKey(newKey));- Schema schema5 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Schema schema5 = ops.loadSchema(NameIdentifierUtil.ofSchema("m1", "c1", name));Map<String, String> props5 = schema5.properties();Assertions.assertFalse(props5.containsKey(newKey));}@@ -311,7 +313,7 @@ public class TestHadoopCatalogOperations {String catalogPath = TEST_ROOT_PATH + "/" + "catalog20";Schema schema = createSchema(name, comment, catalogPath, null);Assertions.assertEquals(name, schema.name());- NameIdentifier id = NameIdentifier.ofSchema("m1", "c1", name);+ NameIdentifier id = NameIdentifierUtil.ofSchema("m1", "c1", name);try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(@@ -369,7 +371,7 @@ public class TestHadoopCatalogOperations {catalogProps.put(HadoopCatalogPropertiesMetadata.LOCATION, catalogPath);}- NameIdentifier schemaIdent = NameIdentifier.ofSchema("m1", "c1", schemaName);+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(catalogProps, null, HADOOP_PROPERTIES_METADATA);if (!ops.schemaExists(schemaIdent)) {@@ -491,7 +493,7 @@ public class TestHadoopCatalogOperations {catalogProps.put(HadoopCatalogPropertiesMetadata.LOCATION, catalogPath);}- NameIdentifier schemaIdent = NameIdentifier.ofSchema("m1", "c1", schemaName);+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", schemaName);try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(catalogProps, null, HADOOP_PROPERTIES_METADATA);if (!ops.schemaExists(schemaIdent)) {@@ -858,7 +860,7 @@ public class TestHadoopCatalogOperations {try (HadoopCatalogOperations ops = new HadoopCatalogOperations(store)) {ops.initialize(props, null, HADOOP_PROPERTIES_METADATA);- NameIdentifier schemaIdent = NameIdentifier.ofSchema("m1", "c1", name);+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema("m1", "c1", name);Map<String, String> schemaProps = Maps.newHashMap();StringIdentifier stringId = StringIdentifier.fromId(idGenerator.nextId());schemaProps = Maps.newHashMap(StringIdentifier.newPropertiesWithId(stringId, schemaProps));diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.javaindex e79432f209..cb03220bbb 100644--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java@@ -6,7 +6,6 @@ package com.datastrato.gravitino.catalog.hadoop.integration.test;import com.datastrato.gravitino.Catalog;import com.datastrato.gravitino.NameIdentifier;-import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.Schema;import com.datastrato.gravitino.client.GravitinoMetalake;import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;@@ -17,6 +16,7 @@ import com.datastrato.gravitino.integration.test.container.ContainerSuite;import com.datastrato.gravitino.integration.test.container.HiveContainer;import com.datastrato.gravitino.integration.test.util.AbstractIT;import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;import java.io.IOException;@@ -376,7 +376,7 @@ public class HadoopCatalogIT extends AbstractIT {NameIdentifier[] nameIdentifiers =catalog.asFilesetCatalog()- .listFilesets(Namespace.ofFileset(metalakeName, catalogName, schemaName));+ .listFilesets(NamespaceUtil.ofFileset(metalakeName, catalogName, schemaName));Assertions.assertEquals(0, nameIdentifiers.length, "should have no fileset");// create fileset1@@ -409,7 +409,7 @@ public class HadoopCatalogIT extends AbstractIT {NameIdentifier[] nameIdentifiers1 =catalog.asFilesetCatalog()- .listFilesets(Namespace.ofFileset(metalakeName, catalogName, schemaName));+ .listFilesets(NamespaceUtil.ofFileset(metalakeName, catalogName, schemaName));Arrays.sort(nameIdentifiers1, Comparator.comparing(NameIdentifier::name));Assertions.assertEquals(2, nameIdentifiers1.length, "should have 2 filesets");Assertions.assertEquals(fileset1.name(), nameIdentifiers1[0].name());diff --git a/catalogs/catalog-kafka/src/main/java/com/datastrato/gravitino/catalog/kafka/KafkaCatalogOperations.java b/catalogs/catalog-kafka/src/main/java/com/datastrato/gravitino/catalog/kafka/KafkaCatalogOperations.javaindex 5133365245..30b29a734e 100644--- a/catalogs/catalog-kafka/src/main/java/com/datastrato/gravitino/catalog/kafka/KafkaCatalogOperations.java+++ b/catalogs/catalog-kafka/src/main/java/com/datastrato/gravitino/catalog/kafka/KafkaCatalogOperations.java@@ -38,6 +38,7 @@ import com.datastrato.gravitino.messaging.TopicChange;import com.datastrato.gravitino.meta.AuditInfo;import com.datastrato.gravitino.meta.SchemaEntity;import com.datastrato.gravitino.storage.IdGenerator;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.datastrato.gravitino.utils.PrincipalUtils;import com.google.common.annotations.VisibleForTesting;import com.google.common.base.Preconditions;@@ -552,7 +553,7 @@ public class KafkaCatalogOperations implements CatalogOperations, SupportsSchemaSchemaEntity.builder().withName(defaultSchemaIdent.name()).withId(uid)- .withNamespace(Namespace.ofSchema(info.namespace().level(0), info.name()))+ .withNamespace(NamespaceUtil.ofSchema(info.namespace().level(0), info.name())).withComment("The default schema of Kafka catalog including all topics").withProperties(properties).withAuditInfo(diff --git a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.javaindex 3164c90479..0fb14e2ec2 100644--- a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java+++ b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java@@ -13,7 +13,6 @@ import static com.datastrato.gravitino.integration.test.container.KafkaContainerimport com.datastrato.gravitino.Catalog;import com.datastrato.gravitino.CatalogChange;import com.datastrato.gravitino.NameIdentifier;-import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.Schema;import com.datastrato.gravitino.SchemaChange;import com.datastrato.gravitino.client.GravitinoMetalake;@@ -23,6 +22,7 @@ import com.datastrato.gravitino.integration.test.util.AbstractIT;import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;import com.datastrato.gravitino.messaging.Topic;import com.datastrato.gravitino.messaging.TopicChange;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;@@ -213,7 +213,7 @@ public class CatalogKafkaIT extends AbstractIT {kafka.asTopicCatalog().listTopics(- Namespace.ofTopic(METALAKE_NAME, catalogName2, DEFAULT_SCHEMA_NAME)));+ NamespaceUtil.ofTopic(METALAKE_NAME, catalogName2, DEFAULT_SCHEMA_NAME)));Assertions.assertTrue(exception.getMessage()@@ -293,7 +293,7 @@ public class CatalogKafkaIT extends AbstractIT {NameIdentifier[] topics =catalog.asTopicCatalog()- .listTopics(Namespace.ofTopic(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME));+ .listTopics(NamespaceUtil.ofTopic(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME));Assertions.assertTrue(topics.length > 0);Assertions.assertTrue(ImmutableList.copyOf(topics).stream().anyMatch(topic -> topic.name().equals(topicName)));@@ -414,7 +414,7 @@ public class CatalogKafkaIT extends AbstractIT {NameIdentifier[] topics =catalog.asTopicCatalog()- .listTopics(Namespace.ofTopic(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME));+ .listTopics(NamespaceUtil.ofTopic(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME));Assertions.assertTrue(Arrays.stream(topics).anyMatch(topic -> topic.name().equals(illegalName)));diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.javaindex 903ba118ae..5771a4bcb9 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java@@ -54,9 +54,12 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements Catalog, SupportsRESTClient restClient) {super(name, type, provider, comment, properties, auditDTO);this.restClient = restClient;- Namespace.checkCatalog(namespace);+ Namespace.check(+ namespace != null && namespace.length() == 1,+ "Catalog namespace must be non-null and have 1 level, the input namespace is %s",+ namespace);this.namespace = namespace;- this.schemaNamespace = Namespace.ofSchema(namespace.level(0), name);+ this.schemaNamespace = Namespace.of(namespace.level(0), name);}@Overridediff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.javaindex e785f96213..6954caa665 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/DTOConverters.java@@ -68,7 +68,7 @@ class DTOConverters {@SuppressWarnings("unchecked")static Catalog toCatalog(String metalake, CatalogDTO catalog, RESTClient client) {- Namespace namespace = Namespace.ofCatalog(metalake);+ Namespace namespace = Namespace.of(metalake);switch (catalog.type()) {case RELATIONAL:return RelationalCatalog.builder()diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/FilesetCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/FilesetCatalog.javaindex 0a620d45bd..ad2dbf9977 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/FilesetCatalog.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/FilesetCatalog.java@@ -65,7 +65,7 @@ public class FilesetCatalog extends BaseSchemaCatalog*/@Overridepublic NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException {- Namespace.checkFileset(namespace);+ checkFilesetNamespace(namespace);EntityListResponse resp =restClient.get(@@ -87,8 +87,7 @@ public class FilesetCatalog extends BaseSchemaCatalog*/@Overridepublic Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {- NameIdentifier.checkFileset(ident);-+ checkFilesetNameIdentifer(ident);FilesetResponse resp =restClient.get(formatFilesetRequestPath(ident.namespace())@@ -127,8 +126,7 @@ public class FilesetCatalog extends BaseSchemaCatalogString storageLocation,Map<String, String> properties)throws NoSuchSchemaException, FilesetAlreadyExistsException {- NameIdentifier.checkFileset(ident);-+ checkFilesetNameIdentifer(ident);FilesetCreateRequest req =FilesetCreateRequest.builder().name(RESTUtils.encodeString(ident.name()))@@ -162,8 +160,7 @@ public class FilesetCatalog extends BaseSchemaCatalog@Overridepublic Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)throws NoSuchFilesetException, IllegalArgumentException {- NameIdentifier.checkFileset(ident);-+ checkFilesetNameIdentifer(ident);List<FilesetUpdateRequest> updates =Arrays.stream(changes).map(DTOConverters::toFilesetUpdateRequest)@@ -194,8 +191,7 @@ public class FilesetCatalog extends BaseSchemaCatalog*/@Overridepublic boolean dropFileset(NameIdentifier ident) {- NameIdentifier.checkFileset(ident);-+ checkFilesetNameIdentifer(ident);DropResponse resp =restClient.delete(formatFilesetRequestPath(ident.namespace()) + "/" + ident.name(),@@ -218,6 +214,30 @@ public class FilesetCatalog extends BaseSchemaCatalog.toString();}+ /**+ * Check whether the namespace of a fileset is valid+ *+ * @param namespace The namespace to check+ */+ static void checkFilesetNamespace(Namespace namespace) {+ Namespace.check(+ namespace != null && namespace.length() == 3,+ "Fileset namespace must be non-null and have 3 level, the input namespace is %s",+ namespace);+ }++ /**+ * Check whether the NameIdentifier of a fileset is valid+ *+ * @param ident The NameIdentifier to check+ */+ static void checkFilesetNameIdentifer(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "NameIdentifer must not be null");+ NameIdentifier.check(+ ident.name() != null && !ident.name().isEmpty(), "NameIdentifer name must not be empty");+ checkFilesetNamespace(ident.namespace());+ }+/*** Create a new builder for the fileset catalog.*@@ -247,7 +267,10 @@ public class FilesetCatalog extends BaseSchemaCatalog@Overridepublic FilesetCatalog build() {- Namespace.checkCatalog(namespace);+ Namespace.check(+ namespace != null && namespace.length() == 1,+ "Catalog namespace must be non-null and have 1 level, the input namespace is %s",+ namespace);Preconditions.checkArgument(restClient != null, "restClient must be set");Preconditions.checkArgument(StringUtils.isNotBlank(name), "name must not be blank");Preconditions.checkArgument(type != null, "type must not be null");diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClientBase.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClientBase.javaindex 56e8a75078..13133558e1 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClientBase.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoClientBase.java@@ -6,6 +6,7 @@package com.datastrato.gravitino.client;import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.Version;import com.datastrato.gravitino.dto.responses.MetalakeResponse;import com.datastrato.gravitino.dto.responses.VersionResponse;@@ -126,7 +127,11 @@ public abstract class GravitinoClientBase implements Closeable {* @throws IllegalNameIdentifierException If the Metalake name is invalid.*/public void checkMetalakeName(String metalakeName) {- NameIdentifier.checkMetalake(NameIdentifier.parse(metalakeName));+ NameIdentifier identifier = NameIdentifier.parse(metalakeName);+ Namespace.check(+ identifier.namespace() != null && identifier.namespace().isEmpty(),+ "Metalake namespace must be non-null and empty, the input namespace is %s",+ identifier.namespace());}/**diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/MessagingCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/MessagingCatalog.javaindex 681d431959..e0030daa0a 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/MessagingCatalog.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/MessagingCatalog.java@@ -69,7 +69,7 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalog*/@Overridepublic NameIdentifier[] listTopics(Namespace namespace) throws NoSuchSchemaException {- Namespace.checkTopic(namespace);+ checkTopicNamespace(namespace);EntityListResponse resp =restClient.get(@@ -92,7 +92,7 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalog*/@Overridepublic Topic loadTopic(NameIdentifier ident) throws NoSuchTopicException {- NameIdentifier.checkTopic(ident);+ checkTopicNameIdentifer(ident);TopicResponse resp =restClient.get(@@ -122,7 +122,7 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalogpublic Topic createTopic(NameIdentifier ident, String comment, DataLayout dataLayout, Map<String, String> properties)throws NoSuchSchemaException, TopicAlreadyExistsException {- NameIdentifier.checkTopic(ident);+ checkTopicNameIdentifer(ident);TopicCreateRequest req =TopicCreateRequest.builder()@@ -155,7 +155,7 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalog@Overridepublic Topic alterTopic(NameIdentifier ident, TopicChange... changes)throws NoSuchTopicException, IllegalArgumentException {- NameIdentifier.checkTopic(ident);+ checkTopicNameIdentifer(ident);List<TopicUpdateRequest> updates =Arrays.stream(changes)@@ -184,7 +184,7 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalog*/@Overridepublic boolean dropTopic(NameIdentifier ident) {- NameIdentifier.checkTopic(ident);+ checkTopicNameIdentifer(ident);DropResponse resp =restClient.delete(@@ -203,6 +203,30 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalogreturn formatSchemaRequestPath(schemaNs) + "/" + ns.level(2) + "/topics";}+ /**+ * Check whether the namespace of a topic is valid+ *+ * @param namespace The namespace to check+ */+ static void checkTopicNamespace(Namespace namespace) {+ Namespace.check(+ namespace != null && namespace.length() == 3,+ "Topic namespace must be non-null and have 3 level, the input namespace is %s",+ namespace);+ }++ /**+ * Check whether the NameIdentifier of a topic is valid+ *+ * @param ident The NameIdentifier to check+ */+ static void checkTopicNameIdentifer(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "NameIdentifer must not be null");+ NameIdentifier.check(+ ident.name() != null && !ident.name().isEmpty(), "NameIdentifer name must not be empty");+ checkTopicNamespace(ident.namespace());+ }+static class Builder extends CatalogDTO.Builder<Builder> {/** The REST client to send the requests. */private RESTClient restClient;@@ -224,7 +248,10 @@ public class MessagingCatalog extends BaseSchemaCatalog implements TopicCatalog@Overridepublic MessagingCatalog build() {- Namespace.checkCatalog(namespace);+ Namespace.check(+ namespace != null && namespace.length() == 1,+ "Catalog namespace must be non-null and have 1 level, the input namespace is %s",+ namespace);Preconditions.checkArgument(StringUtils.isNotBlank(name), "name must not be blank");Preconditions.checkArgument(type != null, "type must not be null");Preconditions.checkArgument(StringUtils.isNotBlank(provider), "provider must not be blank");diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.javaindex dfceede69a..95f1091727 100644--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java@@ -73,7 +73,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog*/@Overridepublic NameIdentifier[] listTables(Namespace namespace) throws NoSuchSchemaException {- Namespace.checkTable(namespace);+ checkTableNamespace(namespace);EntityListResponse resp =restClient.get(@@ -95,7 +95,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog*/@Overridepublic Table loadTable(NameIdentifier ident) throws NoSuchTableException {- NameIdentifier.checkTable(ident);+ checkTableNameIdentifer(ident);TableResponse resp =restClient.get(@@ -132,7 +132,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalogSortOrder[] sortOrders,Index[] indexes)throws NoSuchSchemaException, TableAlreadyExistsException {- NameIdentifier.checkTable(ident);+ checkTableNameIdentifer(ident);TableCreateRequest req =new TableCreateRequest(@@ -170,7 +170,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog@Overridepublic Table alterTable(NameIdentifier ident, TableChange... changes)throws NoSuchTableException, IllegalArgumentException {- NameIdentifier.checkTable(ident);+ checkTableNameIdentifer(ident);List<TableUpdateRequest> reqs =Arrays.stream(changes)@@ -199,7 +199,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog*/@Overridepublic boolean dropTable(NameIdentifier ident) {- NameIdentifier.checkTable(ident);+ checkTableNameIdentifer(ident);DropResponse resp =restClient.delete(@@ -219,7 +219,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog*/@Overridepublic boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationException {- NameIdentifier.checkTable(ident);+ checkTableNameIdentifer(ident);Map<String, String> params = new HashMap<>();params.put("purge", "true");@@ -253,6 +253,30 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog.toString();}+ /**+ * Check whether the namespace of a table is valid+ *+ * @param namespace The namespace to check+ */+ static void checkTableNamespace(Namespace namespace) {+ Namespace.check(+ namespace != null && namespace.length() == 3,+ "Table namespace must be non-null and have 3 level, the input namespace is %s",+ namespace);+ }++ /**+ * Check whether the NameIdentifier of a table is valid+ *+ * @param ident The NameIdentifier to check+ */+ static void checkTableNameIdentifer(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "NameIdentifer must not be null");+ NameIdentifier.check(+ ident.name() != null && !ident.name().isEmpty(), "NameIdentifer name must not be empty");+ checkTableNamespace(ident.namespace());+ }+/*** Create a new builder for the relational catalog.*@@ -282,7 +306,10 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog@Overridepublic RelationalCatalog build() {- Namespace.checkCatalog(namespace);+ Namespace.check(+ namespace != null && namespace.length() == 1,+ "Catalog namespace must be non-null and have 1 level, the input namespace is %s",+ namespace);Preconditions.checkArgument(restClient != null, "restClient must be set");Preconditions.checkArgument(StringUtils.isNotBlank(name), "name must not be blank");Preconditions.checkArgument(type != null, "type must not be null");diff --git a/clients/filesystem-hadoop3/src/main/java/com/datastrato/gravitino/filesystem/hadoop/GravitinoVirtualFileSystem.java b/clients/filesystem-hadoop3/src/main/java/com/datastrato/gravitino/filesystem/hadoop/GravitinoVirtualFileSystem.javaindex 92f0152cac..32ec1b9717 100644--- a/clients/filesystem-hadoop3/src/main/java/com/datastrato/gravitino/filesystem/hadoop/GravitinoVirtualFileSystem.java+++ b/clients/filesystem-hadoop3/src/main/java/com/datastrato/gravitino/filesystem/hadoop/GravitinoVirtualFileSystem.java@@ -333,8 +333,7 @@ public class GravitinoVirtualFileSystem extends FileSystem {"URI %s doesn't contains valid identifier",virtualPath);- return NameIdentifier.ofFileset(- metalakeName, matcher.group(1), matcher.group(2), matcher.group(3));+ return NameIdentifier.of(metalakeName, matcher.group(1), matcher.group(2), matcher.group(3));}private FilesetContext getFilesetContext(Path virtualPath) {diff --git a/clients/filesystem-hadoop3/src/test/java/com/datastrato/gravitino/filesystem/hadoop/TestGvfsBase.java b/clients/filesystem-hadoop3/src/test/java/com/datastrato/gravitino/filesystem/hadoop/TestGvfsBase.javaindex c77981ad07..31d8ebad03 100644--- a/clients/filesystem-hadoop3/src/test/java/com/datastrato/gravitino/filesystem/hadoop/TestGvfsBase.java+++ b/clients/filesystem-hadoop3/src/test/java/com/datastrato/gravitino/filesystem/hadoop/TestGvfsBase.java@@ -504,50 +504,41 @@ public class TestGvfsBase extends GravitinoMockServerBase {(GravitinoVirtualFileSystem) managedFilesetPath.getFileSystem(conf)) {NameIdentifier identifier =fs.extractIdentifier(new URI("gvfs://fileset/catalog1/schema1/fileset1"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier);NameIdentifier identifier2 =fs.extractIdentifier(new URI("gvfs://fileset/catalog1/schema1/fileset1/"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier2);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier2);NameIdentifier identifier3 =fs.extractIdentifier(new URI("gvfs://fileset/catalog1/schema1/fileset1/files"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier3);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier3);NameIdentifier identifier4 =fs.extractIdentifier(new URI("gvfs://fileset/catalog1/schema1/fileset1/dir/dir"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier4);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier4);NameIdentifier identifier5 =fs.extractIdentifier(new URI("gvfs://fileset/catalog1/schema1/fileset1/dir/dir/"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier5);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier5);NameIdentifier identifier6 = fs.extractIdentifier(new URI("/catalog1/schema1/fileset1"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier6);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier6);NameIdentifier identifier7 = fs.extractIdentifier(new URI("/catalog1/schema1/fileset1/"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier7);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier7);NameIdentifier identifier8 = fs.extractIdentifier(new URI("/catalog1/schema1/fileset1/dir"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier8);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier8);NameIdentifier identifier9 =fs.extractIdentifier(new URI("/catalog1/schema1/fileset1/dir/dir/"));- assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier9);+ assertEquals(NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier9);NameIdentifier identifier10 =fs.extractIdentifier(new URI("/catalog1/schema1/fileset1/dir/dir"));assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier10);+ NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier10);StringBuilder longUri = new StringBuilder("gvfs://fileset/catalog1/schema1/fileset1");for (int i = 0; i < 1500; i++) {@@ -555,11 +546,11 @@ public class TestGvfsBase extends GravitinoMockServerBase {}NameIdentifier identifier11 = fs.extractIdentifier(new URI(longUri.toString()));assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier11);+ NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier11);NameIdentifier identifier12 = fs.extractIdentifier(new URI(longUri.delete(0, 14).toString()));assertEquals(- NameIdentifier.ofFileset(metalakeName, "catalog1", "schema1", "fileset1"), identifier12);+ NameIdentifier.of(metalakeName, "catalog1", "schema1", "fileset1"), identifier12);assertThrows(IllegalArgumentException.class,diff --git a/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java b/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.javaindex ad9db0d0b5..ef66a30bfe 100644--- a/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java+++ b/core/src/main/java/com/datastrato/gravitino/authorization/AuthorizationUtils.java@@ -29,7 +29,7 @@ public class AuthorizationUtils {try {EntityStore store = GravitinoEnv.getInstance().entityStore();- NameIdentifier metalakeIdent = NameIdentifier.ofMetalake(metalake);+ NameIdentifier metalakeIdent = NameIdentifier.of(metalake);if (!store.exists(metalakeIdent, Entity.EntityType.METALAKE)) {LOG.warn("Metalake {} does not exist", metalakeIdent);throw new NoSuchMetalakeException(METALAKE_DOES_NOT_EXIST_MSG, metalakeIdent);diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.javaindex 87e36036ec..d0546346b2 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java@@ -506,7 +506,7 @@ public class CatalogManager implements CatalogDispatcher, Closeable {// Kafka catalog needs to cascade drop the default schemaList<SchemaEntity> schemas =store.list(- Namespace.ofSchema(ident.namespace().level(0), ident.name()),+ Namespace.of(ident.namespace().level(0), ident.name()),SchemaEntity.class,EntityType.SCHEMA);// If there is only one schema, it must be the default schema, because we don't allow todiff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.javaindex 9264fac346..418ff06f1c 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java@@ -22,6 +22,8 @@ import com.datastrato.gravitino.storage.relational.po.CatalogPO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -71,7 +73,7 @@ public class CatalogMetaService {}public CatalogEntity getCatalogByIdentifier(NameIdentifier identifier) {- NameIdentifier.checkCatalog(identifier);+ NameIdentifierUtil.checkCatalog(identifier);String catalogName = identifier.name();Long metalakeId =@@ -83,7 +85,7 @@ public class CatalogMetaService {}public List<CatalogEntity> listCatalogsByNamespace(Namespace namespace) {- Namespace.checkCatalog(namespace);+ NamespaceUtil.checkCatalog(namespace);Long metalakeId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);@@ -96,7 +98,7 @@ public class CatalogMetaService {public void insertCatalog(CatalogEntity catalogEntity, boolean overwrite) {try {- NameIdentifier.checkCatalog(catalogEntity.nameIdentifier());+ NameIdentifierUtil.checkCatalog(catalogEntity.nameIdentifier());Long metalakeId =CommonMetaService.getInstance().getParentEntityIdByNamespace(catalogEntity.namespace());@@ -120,7 +122,7 @@ public class CatalogMetaService {public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog(NameIdentifier identifier, Function<E, E> updater) throws IOException {- NameIdentifier.checkCatalog(identifier);+ NameIdentifierUtil.checkCatalog(identifier);String catalogName = identifier.name();Long metalakeId =@@ -160,7 +162,7 @@ public class CatalogMetaService {}public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {- NameIdentifier.checkCatalog(identifier);+ NameIdentifierUtil.checkCatalog(identifier);String catalogName = identifier.name();Long metalakeId =@@ -198,7 +200,7 @@ public class CatalogMetaService {List<SchemaEntity> schemaEntities =SchemaMetaService.getInstance().listSchemasByNamespace(- Namespace.ofSchema(identifier.namespace().level(0), catalogName));+ NamespaceUtil.ofSchema(identifier.namespace().level(0), catalogName));if (!schemaEntities.isEmpty()) {throw new NonEmptyEntityException("Entity %s has sub-entities, you should remove sub-entities first", identifier);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.javaindex 058b746470..8da9c9fdf9 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java@@ -17,6 +17,8 @@ import com.datastrato.gravitino.storage.relational.po.FilesetPO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -71,7 +73,7 @@ public class FilesetMetaService {}public FilesetEntity getFilesetByIdentifier(NameIdentifier identifier) {- NameIdentifier.checkFileset(identifier);+ NameIdentifierUtil.checkFileset(identifier);String filesetName = identifier.name();@@ -84,7 +86,7 @@ public class FilesetMetaService {}public List<FilesetEntity> listFilesetsByNamespace(Namespace namespace) {- Namespace.checkFileset(namespace);+ NamespaceUtil.checkFileset(namespace);Long schemaId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);@@ -97,7 +99,7 @@ public class FilesetMetaService {public void insertFileset(FilesetEntity filesetEntity, boolean overwrite) {try {- NameIdentifier.checkFileset(filesetEntity.nameIdentifier());+ NameIdentifierUtil.checkFileset(filesetEntity.nameIdentifier());FilesetPO.Builder builder = FilesetPO.builder();fillFilesetPOBuilderParentEntityId(builder, filesetEntity.namespace());@@ -135,7 +137,7 @@ public class FilesetMetaService {public <E extends Entity & HasIdentifier> FilesetEntity updateFileset(NameIdentifier identifier, Function<E, E> updater) throws IOException {- NameIdentifier.checkFileset(identifier);+ NameIdentifierUtil.checkFileset(identifier);String filesetName = identifier.name();@@ -195,7 +197,7 @@ public class FilesetMetaService {}public boolean deleteFileset(NameIdentifier identifier) {- NameIdentifier.checkFileset(identifier);+ NameIdentifierUtil.checkFileset(identifier);String filesetName = identifier.name();@@ -267,7 +269,7 @@ public class FilesetMetaService {}private void fillFilesetPOBuilderParentEntityId(FilesetPO.Builder builder, Namespace namespace) {- Namespace.checkFileset(namespace);+ NamespaceUtil.checkFileset(namespace);Long parentEntityId = null;for (int level = 0; level < namespace.levels().length; level++) {String name = namespace.level(level);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.javaindex 077e455519..d6055033ff 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java@@ -8,7 +8,6 @@ package com.datastrato.gravitino.storage.relational.service;import com.datastrato.gravitino.Entity;import com.datastrato.gravitino.HasIdentifier;import com.datastrato.gravitino.NameIdentifier;-import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.exceptions.NoSuchEntityException;import com.datastrato.gravitino.exceptions.NonEmptyEntityException;import com.datastrato.gravitino.meta.BaseMetalake;@@ -29,6 +28,8 @@ import com.datastrato.gravitino.storage.relational.po.MetalakePO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -68,7 +69,7 @@ public class MetalakeMetaService {}public BaseMetalake getMetalakeByIdentifier(NameIdentifier ident) {- NameIdentifier.checkMetalake(ident);+ NameIdentifierUtil.checkMetalake(ident);MetalakePO metalakePO =SessionUtils.getWithoutCommit(MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeMetaByName(ident.name()));@@ -83,7 +84,7 @@ public class MetalakeMetaService {public void insertMetalake(BaseMetalake baseMetalake, boolean overwrite) {try {- NameIdentifier.checkMetalake(baseMetalake.nameIdentifier());+ NameIdentifierUtil.checkMetalake(baseMetalake.nameIdentifier());SessionUtils.doWithCommit(MetalakeMetaMapper.class,mapper -> {@@ -103,7 +104,7 @@ public class MetalakeMetaService {public <E extends Entity & HasIdentifier> BaseMetalake updateMetalake(NameIdentifier ident, Function<E, E> updater) throws IOException {- NameIdentifier.checkMetalake(ident);+ NameIdentifierUtil.checkMetalake(ident);MetalakePO oldMetalakePO =SessionUtils.getWithoutCommit(MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeMetaByName(ident.name()));@@ -143,7 +144,7 @@ public class MetalakeMetaService {}public boolean deleteMetalake(NameIdentifier ident, boolean cascade) {- NameIdentifier.checkMetalake(ident);+ NameIdentifierUtil.checkMetalake(ident);Long metalakeId = getMetalakeIdByName(ident.name());if (metalakeId != null) {if (cascade) {@@ -199,7 +200,7 @@ public class MetalakeMetaService {} else {List<CatalogEntity> catalogEntities =CatalogMetaService.getInstance()- .listCatalogsByNamespace(Namespace.ofCatalog(ident.name()));+ .listCatalogsByNamespace(NamespaceUtil.ofCatalog(ident.name()));if (!catalogEntities.isEmpty()) {throw new NonEmptyEntityException("Entity %s has sub-entities, you should remove sub-entities first", ident);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.javaindex a5ae106388..14b53d121f 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java@@ -22,6 +22,8 @@ import com.datastrato.gravitino.storage.relational.po.SchemaPO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -69,7 +71,7 @@ public class SchemaMetaService {}public SchemaEntity getSchemaByIdentifier(NameIdentifier identifier) {- NameIdentifier.checkSchema(identifier);+ NameIdentifierUtil.checkSchema(identifier);String schemaName = identifier.name();Long catalogId =@@ -81,7 +83,7 @@ public class SchemaMetaService {}public List<SchemaEntity> listSchemasByNamespace(Namespace namespace) {- Namespace.checkSchema(namespace);+ NamespaceUtil.checkSchema(namespace);Long catalogId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);@@ -93,7 +95,7 @@ public class SchemaMetaService {public void insertSchema(SchemaEntity schemaEntity, boolean overwrite) {try {- NameIdentifier.checkSchema(schemaEntity.nameIdentifier());+ NameIdentifierUtil.checkSchema(schemaEntity.nameIdentifier());SchemaPO.Builder builder = SchemaPO.builder();fillSchemaPOBuilderParentEntityId(builder, schemaEntity.namespace());@@ -117,7 +119,7 @@ public class SchemaMetaService {public <E extends Entity & HasIdentifier> SchemaEntity updateSchema(NameIdentifier identifier, Function<E, E> updater) throws IOException {- NameIdentifier.checkSchema(identifier);+ NameIdentifierUtil.checkSchema(identifier);String schemaName = identifier.name();Long catalogId =@@ -155,7 +157,7 @@ public class SchemaMetaService {}public boolean deleteSchema(NameIdentifier identifier, boolean cascade) {- NameIdentifier.checkSchema(identifier);+ NameIdentifierUtil.checkSchema(identifier);String schemaName = identifier.name();Long catalogId =@@ -189,7 +191,7 @@ public class SchemaMetaService {List<TableEntity> tableEntities =TableMetaService.getInstance().listTablesByNamespace(- Namespace.ofTable(+ NamespaceUtil.ofTable(identifier.namespace().level(0),identifier.namespace().level(1),schemaName));@@ -200,7 +202,7 @@ public class SchemaMetaService {List<FilesetEntity> filesetEntities =FilesetMetaService.getInstance().listFilesetsByNamespace(- Namespace.ofFileset(+ NamespaceUtil.ofFileset(identifier.namespace().level(0),identifier.namespace().level(1),schemaName));@@ -224,7 +226,7 @@ public class SchemaMetaService {}private void fillSchemaPOBuilderParentEntityId(SchemaPO.Builder builder, Namespace namespace) {- Namespace.checkSchema(namespace);+ NamespaceUtil.checkSchema(namespace);Long parentEntityId = null;for (int level = 0; level < namespace.levels().length; level++) {String name = namespace.level(level);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.javaindex f71bbc41b1..47d9d0ea83 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TableMetaService.java@@ -15,6 +15,8 @@ import com.datastrato.gravitino.storage.relational.po.TablePO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -62,7 +64,7 @@ public class TableMetaService {}public TableEntity getTableByIdentifier(NameIdentifier identifier) {- NameIdentifier.checkTable(identifier);+ NameIdentifierUtil.checkTable(identifier);Long schemaId =CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());@@ -73,7 +75,7 @@ public class TableMetaService {}public List<TableEntity> listTablesByNamespace(Namespace namespace) {- Namespace.checkTable(namespace);+ NamespaceUtil.checkTable(namespace);Long schemaId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);@@ -86,7 +88,7 @@ public class TableMetaService {public void insertTable(TableEntity tableEntity, boolean overwrite) {try {- NameIdentifier.checkTable(tableEntity.nameIdentifier());+ NameIdentifierUtil.checkTable(tableEntity.nameIdentifier());TablePO.Builder builder = TablePO.builder();fillTablePOBuilderParentEntityId(builder, tableEntity.namespace());@@ -110,7 +112,7 @@ public class TableMetaService {public <E extends Entity & HasIdentifier> TableEntity updateTable(NameIdentifier identifier, Function<E, E> updater) throws IOException {- NameIdentifier.checkTable(identifier);+ NameIdentifierUtil.checkTable(identifier);String tableName = identifier.name();@@ -148,7 +150,7 @@ public class TableMetaService {}public boolean deleteTable(NameIdentifier identifier) {- NameIdentifier.checkTable(identifier);+ NameIdentifierUtil.checkTable(identifier);String tableName = identifier.name();@@ -172,7 +174,7 @@ public class TableMetaService {}private void fillTablePOBuilderParentEntityId(TablePO.Builder builder, Namespace namespace) {- Namespace.checkTable(namespace);+ NamespaceUtil.checkTable(namespace);Long parentEntityId = null;for (int level = 0; level < namespace.levels().length; level++) {String name = namespace.level(level);diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.javaindex 06042a9659..b79db5ea80 100644--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/TopicMetaService.java@@ -15,6 +15,8 @@ import com.datastrato.gravitino.storage.relational.po.TopicPO;import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;import com.datastrato.gravitino.storage.relational.utils.POConverters;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.base.Preconditions;import java.io.IOException;import java.util.List;@@ -36,7 +38,7 @@ public class TopicMetaService {public void insertTopic(TopicEntity topicEntity, boolean overwrite) {try {- NameIdentifier.checkTopic(topicEntity.nameIdentifier());+ NameIdentifierUtil.checkTopic(topicEntity.nameIdentifier());TopicPO.Builder builder = TopicPO.builder();fillTopicPOBuilderParentEntityId(builder, topicEntity.namespace());@@ -60,7 +62,7 @@ public class TopicMetaService {}public List<TopicEntity> listTopicsByNamespace(Namespace namespace) {- Namespace.checkTopic(namespace);+ NamespaceUtil.checkTopic(namespace);Long schemaId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);@@ -73,7 +75,7 @@ public class TopicMetaService {public <E extends Entity & HasIdentifier> TopicEntity updateTopic(NameIdentifier ident, Function<E, E> updater) throws IOException {- NameIdentifier.checkTopic(ident);+ NameIdentifierUtil.checkTopic(ident);String topicName = ident.name();@@ -125,7 +127,7 @@ public class TopicMetaService {}private void fillTopicPOBuilderParentEntityId(TopicPO.Builder builder, Namespace namespace) {- Namespace.checkTopic(namespace);+ NamespaceUtil.checkTopic(namespace);Long parentEntityId = null;for (int level = 0; level < namespace.levels().length; level++) {String name = namespace.level(level);@@ -150,7 +152,7 @@ public class TopicMetaService {}public TopicEntity getTopicByIdentifier(NameIdentifier identifier) {- NameIdentifier.checkTopic(identifier);+ NameIdentifierUtil.checkTopic(identifier);Long schemaId =CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());@@ -161,7 +163,7 @@ public class TopicMetaService {}public boolean deleteTopic(NameIdentifier identifier) {- NameIdentifier.checkTopic(identifier);+ NameIdentifierUtil.checkTopic(identifier);String topicName = identifier.name();diff --git a/core/src/main/java/com/datastrato/gravitino/utils/NameIdentifierUtil.java b/core/src/main/java/com/datastrato/gravitino/utils/NameIdentifierUtil.javanew file mode 100644index 0000000000..648e66561d--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/utils/NameIdentifierUtil.java@@ -0,0 +1,182 @@+/*+ * Copyright 2023 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.utils;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.exceptions.IllegalNameIdentifierException;+import com.datastrato.gravitino.exceptions.IllegalNamespaceException;+import com.google.errorprone.annotations.FormatMethod;+import com.google.errorprone.annotations.FormatString;++/**+ * A name identifier is a sequence of names separated by dots. It's used to identify a metalake, a+ * catalog, a schema or a table. For example, "metalake1" can represent a metalake,+ * "metalake1.catalog1" can represent a catalog, "metalake1.catalog1.schema1" can represent a+ * schema.+ */+public class NameIdentifierUtil {++ private NameIdentifierUtil() {}++ /**+ * Create the metalake {@link NameIdentifierUtil} with the given name.+ *+ * @param metalake The metalake name+ * @return The created metalake {@link NameIdentifier}+ */+ public static NameIdentifier ofMetalake(String metalake) {+ return NameIdentifier.of(metalake);+ }++ /**+ * Create the catalog {@link NameIdentifierUtil} with the given metalake and catalog name.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @return The created catalog {@link NameIdentifier}+ */+ public static NameIdentifier ofCatalog(String metalake, String catalog) {+ return NameIdentifier.of(metalake, catalog);+ }++ /**+ * Create the schema {@link NameIdentifierUtil} with the given metalake, catalog and schema name.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @return The created schema {@link NameIdentifierUtil}+ */+ public static NameIdentifier ofSchema(String metalake, String catalog, String schema) {+ return NameIdentifier.of(metalake, catalog, schema);+ }++ /**+ * Create the table {@link NameIdentifier} with the given metalake, catalog, schema and table+ * name.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @param table The table name+ * @return The created table {@link NameIdentifier}+ */+ public static NameIdentifier ofTable(+ String metalake, String catalog, String schema, String table) {+ return NameIdentifier.of(metalake, catalog, schema, table);+ }++ /**+ * Create the fileset {@link NameIdentifier} with the given metalake, catalog, schema and fileset+ * name.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @param fileset The fileset name+ * @return The created fileset {@link NameIdentifier}+ */+ public static NameIdentifier ofFileset(+ String metalake, String catalog, String schema, String fileset) {+ return NameIdentifier.of(metalake, catalog, schema, fileset);+ }++ /**+ * Create the topic {@link NameIdentifier} with the given metalake, catalog, schema and topic+ * name.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @param topic The topic name+ * @return The created topic {@link NameIdentifier}+ */+ public static NameIdentifier ofTopic(+ String metalake, String catalog, String schema, String topic) {+ return NameIdentifier.of(metalake, catalog, schema, topic);+ }++ /**+ * Check the given {@link NameIdentifier} is a metalake identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The metalake {@link NameIdentifier} to check.+ */+ public static void checkMetalake(NameIdentifier ident) {+ // We don't have to check the name field of NameIdentifier, it's already checked when+ // creating NameIdentifier object.+ NameIdentifier.check(ident != null, "Metalake identifier must not be null");+ NamespaceUtil.checkMetalake(ident.namespace());+ }++ /**+ * Check the given {@link NameIdentifier} is a catalog identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The catalog {@link NameIdentifier} to check.+ */+ public static void checkCatalog(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "Catalog identifier must not be null");+ NamespaceUtil.checkCatalog(ident.namespace());+ }++ /**+ * Check the given {@link NameIdentifier} is a schema identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The schema {@link NameIdentifier} to check.+ */+ public static void checkSchema(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "Schema identifier must not be null");+ NamespaceUtil.checkSchema(ident.namespace());+ }++ /**+ * Check the given {@link NameIdentifier} is a table identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The table {@link NameIdentifier} to check.+ */+ public static void checkTable(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "Table identifier must not be null");+ NamespaceUtil.checkTable(ident.namespace());+ }++ /**+ * Check the given {@link NameIdentifier} is a fileset identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The fileset {@link NameIdentifier} to check.+ */+ public static void checkFileset(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "Fileset identifier must not be null");+ NamespaceUtil.checkFileset(ident.namespace());+ }++ /**+ * Check the given {@link NameIdentifier} is a topic identifier. Throw an {@link+ * IllegalNameIdentifierException} if it's not.+ *+ * @param ident The topic {@link NameIdentifier} to check.+ */+ public static void checkTopic(NameIdentifier ident) {+ NameIdentifier.check(ident != null, "Topic identifier must not be null");+ NamespaceUtil.checkTopic(ident.namespace());+ }++ /**+ * Check the given condition is true. Throw an {@link IllegalNamespaceException} if it's not.+ *+ * @param expression The expression to check.+ * @param message The message to throw.+ * @param args The arguments to the message.+ */+ @FormatMethod+ public static void check(boolean expression, @FormatString String message, Object... args) {+ if (!expression) {+ throw new IllegalNamespaceException(message, args);+ }+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/utils/NamespaceUtil.java b/core/src/main/java/com/datastrato/gravitino/utils/NamespaceUtil.javanew file mode 100644index 0000000000..fca06dc97c--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/utils/NamespaceUtil.java@@ -0,0 +1,174 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.utils;++import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.exceptions.IllegalNamespaceException;+import com.google.errorprone.annotations.FormatMethod;+import com.google.errorprone.annotations.FormatString;++/** Utility class for namespace. */+public class NamespaceUtil {++ private NamespaceUtil() {}++ /**+ * Create a namespace for metalake.+ *+ * @return A namespace for metalake+ */+ public static Namespace ofMetalake() {+ return Namespace.empty();+ }++ /**+ * Create a namespace for catalog.+ *+ * @param metalake The metalake name+ * @return A namespace for catalog+ */+ public static Namespace ofCatalog(String metalake) {+ return Namespace.of(metalake);+ }++ /**+ * Create a namespace for schema.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @return A namespace for schema+ */+ public static Namespace ofSchema(String metalake, String catalog) {+ return Namespace.of(metalake, catalog);+ }++ /**+ * Create a namespace for table.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @return A namespace for table+ */+ public static Namespace ofTable(String metalake, String catalog, String schema) {+ return Namespace.of(metalake, catalog, schema);+ }++ /**+ * Create a namespace for fileset.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @return A namespace for fileset+ */+ public static Namespace ofFileset(String metalake, String catalog, String schema) {+ return Namespace.of(metalake, catalog, schema);+ }++ /**+ * Create a namespace for topic.+ *+ * @param metalake The metalake name+ * @param catalog The catalog name+ * @param schema The schema name+ * @return A namespace for topic+ */+ public static Namespace ofTopic(String metalake, String catalog, String schema) {+ return Namespace.of(metalake, catalog, schema);+ }++ /**+ * Check if the given metalake namespace is legal, throw an {@link IllegalNamespaceException} if+ * it's illegal.+ *+ * @param namespace The metalake namespace+ */+ public static void checkMetalake(Namespace namespace) {+ check(+ namespace != null && namespace.isEmpty(),+ "Metalake namespace must be non-null and empty, the input namespace is %s",+ namespace);+ }++ /**+ * Check if the given catalog namespace is legal, throw an {@link IllegalNamespaceException} if+ * it's illegal.+ *+ * @param namespace The catalog namespace+ */+ public static void checkCatalog(Namespace namespace) {+ check(+ namespace != null && namespace.length() == 1,+ "Catalog namespace must be non-null and have 1 level, the input namespace is %s",+ namespace);+ }++ /**+ * Check if the given schema namespace is legal, throw an {@link IllegalNamespaceException} if+ * it's illegal.+ *+ * @param namespace The schema namespace+ */+ public static void checkSchema(Namespace namespace) {+ check(+ namespace != null && namespace.length() == 2,+ "Schema namespace must be non-null and have 2 levels, the input namespace is %s",+ namespace);+ }++ /**+ * Check if the given table namespace is legal, throw an {@link IllegalNamespaceException} if it's+ * illegal.+ *+ * @param namespace The table namespace+ */+ public static void checkTable(Namespace namespace) {+ check(+ namespace != null && namespace.length() == 3,+ "Table namespace must be non-null and have 3 levels, the input namespace is %s",+ namespace);+ }++ /**+ * Check if the given fileset namespace is legal, throw an {@link IllegalNamespaceException} if+ * it's illegal.+ *+ * @param namespace The fileset namespace+ */+ public static void checkFileset(Namespace namespace) {+ check(+ namespace != null && namespace.length() == 3,+ "Fileset namespace must be non-null and have 3 levels, the input namespace is %s",+ namespace);+ }++ /**+ * Check if the given topic namespace is legal, throw an {@link IllegalNamespaceException} if it's+ * illegal.+ *+ * @param namespace The topic namespace+ */+ public static void checkTopic(Namespace namespace) {+ check(+ namespace != null && namespace.length() == 3,+ "Topic namespace must be non-null and have 3 levels, the input namespace is %s",+ namespace);+ }++ /**+ * Check the given condition is true. Throw an {@link IllegalNamespaceException} if it's not.+ *+ * @param expression The expression to check.+ * @param message The message to throw.+ * @param args The arguments to the message.+ */+ @FormatMethod+ public static void check(boolean expression, @FormatString String message, Object... args) {+ if (!expression) {+ throw new IllegalNamespaceException(message, args);+ }+ }+}diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionNormalizeDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionNormalizeDispatcher.javaindex 746afb2d2c..e9c94ba449 100644--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionNormalizeDispatcher.java+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionNormalizeDispatcher.java@@ -11,6 +11,7 @@ import com.datastrato.gravitino.rel.expressions.literals.Literals;import com.datastrato.gravitino.rel.partitions.Partition;import com.datastrato.gravitino.rel.partitions.Partitions;import com.datastrato.gravitino.rel.types.Types;+import com.datastrato.gravitino.utils.NameIdentifierUtil;import com.google.common.collect.Maps;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.BeforeAll;@@ -21,7 +22,7 @@ public class TestPartitionNormalizeDispatcher extends TestOperationDispatcher {private static PartitionNormalizeDispatcher partitionNormalizeDispatcher;private static final String SCHEMA = "test_partition_normalize_schema";private static final NameIdentifier TABLE =- NameIdentifier.ofTable(metalake, catalog, SCHEMA, "TEST_PARTITION_NORMALIZE_TABLE");+ NameIdentifierUtil.ofTable(metalake, catalog, SCHEMA, "TEST_PARTITION_NORMALIZE_TABLE");@BeforeAllpublic static void initialize() {@@ -29,11 +30,11 @@ public class TestPartitionNormalizeDispatcher extends TestOperationDispatcher {partitionNormalizeDispatcher =new PartitionNormalizeDispatcher(TestPartitionOperationDispatcher.partitionOperationDispatcher);- NameIdentifier schemaIdent = NameIdentifier.ofSchema(metalake, catalog, SCHEMA);+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema(metalake, catalog, SCHEMA);TestPartitionOperationDispatcher.schemaOperationDispatcher.createSchema(schemaIdent, "comment", null);NameIdentifier tableIdent =- NameIdentifier.ofTable(metalake, catalog, SCHEMA, "test_partition_normalize_table");+ NameIdentifierUtil.ofTable(metalake, catalog, SCHEMA, "test_partition_normalize_table");TestPartitionOperationDispatcher.tableOperationDispatcher.createTable(tableIdent,new Column[] {diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionOperationDispatcher.javaindex 926eb15e7c..b683e11b14 100644--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionOperationDispatcher.java+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestPartitionOperationDispatcher.java@@ -12,6 +12,7 @@ import com.datastrato.gravitino.rel.partitions.Partition;import com.datastrato.gravitino.rel.partitions.Partitions;import com.datastrato.gravitino.rel.types.Types;import com.datastrato.gravitino.utils.IsolatedClassLoader;+import com.datastrato.gravitino.utils.NameIdentifierUtil;import com.google.common.collect.Maps;import java.util.Arrays;import org.junit.jupiter.api.Assertions;@@ -26,7 +27,7 @@ public class TestPartitionOperationDispatcher extends TestOperationDispatcher {private static final String SCHEMA = "test_partition_schema";private static final String TABLE = "test_partition_table";private static final NameIdentifier TABLE_IDENT =- NameIdentifier.ofTable(metalake, catalog, SCHEMA, TABLE);+ NameIdentifierUtil.ofTable(metalake, catalog, SCHEMA, TABLE);private static final Partition PARTITION =Partitions.identity("p1",@@ -59,7 +60,7 @@ public class TestPartitionOperationDispatcher extends TestOperationDispatcher {partitionOperationDispatcher =new PartitionOperationDispatcher(catalogManager, entityStore, idGenerator);- NameIdentifier schemaIdent = NameIdentifier.ofSchema(metalake, catalog, SCHEMA);+ NameIdentifier schemaIdent = NameIdentifierUtil.ofSchema(metalake, catalog, SCHEMA);schemaOperationDispatcher.createSchema(schemaIdent, "comment", null);Column[] columns =new Column[] {diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.javaindex a928782a73..d9cb21d079 100644--- a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java+++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestJDBCBackend.java@@ -45,6 +45,7 @@ import com.datastrato.gravitino.storage.relational.mapper.UserMetaMapper;import com.datastrato.gravitino.storage.relational.service.RoleMetaService;import com.datastrato.gravitino.storage.relational.session.SqlSessionFactoryHelper;import com.datastrato.gravitino.storage.relational.utils.SessionUtils;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Lists;import java.io.File;@@ -202,13 +203,13 @@ public class TestJDBCBackend {CatalogEntity catalog =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("metalake"),+ NamespaceUtil.ofCatalog("metalake"),"catalog",auditInfo);CatalogEntity catalogCopy =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("metalake"),+ NamespaceUtil.ofCatalog("metalake"),"catalog",auditInfo);backend.insert(catalog, false);@@ -217,13 +218,13 @@ public class TestJDBCBackend {SchemaEntity schema =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("metalake", "catalog"),+ NamespaceUtil.ofSchema("metalake", "catalog"),"schema",auditInfo);SchemaEntity schemaCopy =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("metalake", "catalog"),+ NamespaceUtil.ofSchema("metalake", "catalog"),"schema",auditInfo);backend.insert(schema, false);@@ -232,13 +233,13 @@ public class TestJDBCBackend {TableEntity table =createTableEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofTable("metalake", "catalog", "schema"),+ NamespaceUtil.ofTable("metalake", "catalog", "schema"),"table",auditInfo);TableEntity tableCopy =createTableEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofTable("metalake", "catalog", "schema"),+ NamespaceUtil.ofTable("metalake", "catalog", "schema"),"table",auditInfo);backend.insert(table, false);@@ -247,13 +248,13 @@ public class TestJDBCBackend {FilesetEntity fileset =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset",auditInfo);FilesetEntity filesetCopy =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset",auditInfo);backend.insert(fileset, false);@@ -262,13 +263,13 @@ public class TestJDBCBackend {TopicEntity topic =createTopicEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"topic",auditInfo);TopicEntity topicCopy =createTopicEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"topic",auditInfo);backend.insert(topic, false);@@ -297,13 +298,13 @@ public class TestJDBCBackend {CatalogEntity catalog =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("metalake"),+ NamespaceUtil.ofCatalog("metalake"),"catalog",auditInfo);CatalogEntity catalogCopy =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("metalake"),+ NamespaceUtil.ofCatalog("metalake"),"catalog1",auditInfo);backend.insert(catalog, false);@@ -321,13 +322,13 @@ public class TestJDBCBackend {SchemaEntity schema =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("metalake", "catalog"),+ NamespaceUtil.ofSchema("metalake", "catalog"),"schema",auditInfo);SchemaEntity schemaCopy =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("metalake", "catalog"),+ NamespaceUtil.ofSchema("metalake", "catalog"),"schema1",auditInfo);backend.insert(schema, false);@@ -345,13 +346,13 @@ public class TestJDBCBackend {TableEntity table =createTableEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofTable("metalake", "catalog", "schema"),+ NamespaceUtil.ofTable("metalake", "catalog", "schema"),"table",auditInfo);TableEntity tableCopy =createTableEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofTable("metalake", "catalog", "schema"),+ NamespaceUtil.ofTable("metalake", "catalog", "schema"),"table1",auditInfo);backend.insert(table, false);@@ -367,13 +368,13 @@ public class TestJDBCBackend {FilesetEntity fileset =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset",auditInfo);FilesetEntity filesetCopy =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset1",auditInfo);backend.insert(fileset, false);@@ -391,13 +392,13 @@ public class TestJDBCBackend {TopicEntity topic =createTopicEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"topic",auditInfo);TopicEntity topicCopy =createTopicEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"topic1",auditInfo);backend.insert(topic, false);@@ -424,7 +425,7 @@ public class TestJDBCBackend {CatalogEntity catalog =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("metalake"),+ NamespaceUtil.ofCatalog("metalake"),"catalog",auditInfo);backend.insert(catalog, false);@@ -432,7 +433,7 @@ public class TestJDBCBackend {SchemaEntity schema =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("metalake", "catalog"),+ NamespaceUtil.ofSchema("metalake", "catalog"),"schema",auditInfo);backend.insert(schema, false);@@ -440,7 +441,7 @@ public class TestJDBCBackend {TableEntity table =createTableEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofTable("metalake", "catalog", "schema"),+ NamespaceUtil.ofTable("metalake", "catalog", "schema"),"table",auditInfo);backend.insert(table, false);@@ -448,7 +449,7 @@ public class TestJDBCBackend {FilesetEntity fileset =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset",auditInfo);backend.insert(fileset, false);@@ -456,7 +457,7 @@ public class TestJDBCBackend {TopicEntity topic =createTopicEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"topic",auditInfo);backend.insert(topic, false);@@ -465,7 +466,7 @@ public class TestJDBCBackend {FilesetEntity filesetV2 =createFilesetEntity(fileset.id(),- Namespace.ofFileset("metalake", "catalog", "schema"),+ NamespaceUtil.ofFileset("metalake", "catalog", "schema"),"fileset",auditInfo);filesetV2.properties().put("version", "2");@@ -507,7 +508,7 @@ public class TestJDBCBackend {CatalogEntity anotherCatalog =createCatalog(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofCatalog("another-metalake"),+ NamespaceUtil.ofCatalog("another-metalake"),"another-catalog",auditInfo);backend.insert(anotherCatalog, false);@@ -515,7 +516,7 @@ public class TestJDBCBackend {SchemaEntity anotherSchema =createSchemaEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofSchema("another-metalake", "another-catalog"),+ NamespaceUtil.ofSchema("another-metalake", "another-catalog"),"another-schema",auditInfo);backend.insert(anotherSchema, false);@@ -523,7 +524,7 @@ public class TestJDBCBackend {FilesetEntity anotherFileset =createFilesetEntity(RandomIdGenerator.INSTANCE.nextId(),- Namespace.ofFileset("another-metalake", "another-catalog", "another-schema"),+ NamespaceUtil.ofFileset("another-metalake", "another-catalog", "another-schema"),"anotherFileset",auditInfo);backend.insert(anotherFileset, false);@@ -531,7 +532,7 @@ public class TestJDBCBackend {FilesetEntity anotherFilesetV2 =createFilesetEntity(anotherFileset.id(),- Namespace.ofFileset("another-metalake", "another-catalog", "another-schema"),+ NamespaceUtil.ofFileset("another-metalake", "another-catalog", "another-schema"),"anotherFileset",auditInfo);anotherFilesetV2.properties().put("version", "2");@@ -541,7 +542,7 @@ public class TestJDBCBackend {FilesetEntity anotherFilesetV3 =createFilesetEntity(anotherFileset.id(),- Namespace.ofFileset("another-metalake", "another-catalog", "another-schema"),+ NamespaceUtil.ofFileset("another-metalake", "another-catalog", "another-schema"),"anotherFileset",auditInfo);anotherFilesetV3.properties().put("version", "3");diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.javaindex 574501383a..d2cd0711c0 100644--- a/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java+++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java@@ -25,6 +25,7 @@ import com.datastrato.gravitino.storage.relational.po.MetalakePO;import com.datastrato.gravitino.storage.relational.po.SchemaPO;import com.datastrato.gravitino.storage.relational.po.TablePO;import com.datastrato.gravitino.storage.relational.po.TopicPO;+import com.datastrato.gravitino.utils.NamespaceUtil;import com.fasterxml.jackson.core.JsonProcessingException;import com.google.common.collect.ImmutableMap;import java.time.Instant;@@ -65,10 +66,10 @@ public class TestPOConverters {CatalogPO catalogPO = createCatalogPO(1L, "test", 1L, "this is test");CatalogEntity expectedCatalog =- createCatalog(1L, "test", Namespace.ofCatalog("test_metalake"), "this is test");+ createCatalog(1L, "test", NamespaceUtil.ofCatalog("test_metalake"), "this is test");CatalogEntity convertedCatalog =- POConverters.fromCatalogPO(catalogPO, Namespace.ofCatalog("test_metalake"));+ POConverters.fromCatalogPO(catalogPO, NamespaceUtil.ofCatalog("test_metalake"));// AssertassertEquals(expectedCatalog.id(), convertedCatalog.id());@@ -88,10 +89,11 @@ public class TestPOConverters {SchemaEntity expectedSchema =createSchema(- 1L, "test", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test");+ 1L, "test", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test");SchemaEntity convertedSchema =- POConverters.fromSchemaPO(schemaPO, Namespace.ofSchema("test_metalake", "test_catalog"));+ POConverters.fromSchemaPO(+ schemaPO, NamespaceUtil.ofSchema("test_metalake", "test_catalog"));// AssertassertEquals(expectedSchema.id(), convertedSchema.id());@@ -107,11 +109,12 @@ public class TestPOConverters {TablePO tablePO = createTablePO(1L, "test", 1L, 1L, 1L);TableEntity expectedTable =- createTable(1L, "test", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 1L, "test", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TableEntity convertedTable =POConverters.fromTablePO(- tablePO, Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ tablePO, NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));// AssertassertEquals(expectedTable.id(), convertedTable.id());@@ -131,14 +134,14 @@ public class TestPOConverters {createFileset(1L,"test",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test","hdfs://localhost/test",new HashMap<>());FilesetEntity convertedFileset =POConverters.fromFilesetPO(- filesetPO, Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"));+ filesetPO, NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"));// AssertassertEquals(expectedFileset.id(), convertedFileset.id());@@ -157,13 +160,13 @@ public class TestPOConverters {createTopic(1L,"test",- Namespace.ofTopic("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofTopic("test_metalake", "test_catalog", "test_schema"),"test comment",ImmutableMap.of("key", "value"));TopicEntity convertedTopic =POConverters.fromTopicPO(- topicPO, Namespace.ofTopic("test_metalake", "test_catalog", "test_schema"));+ topicPO, NamespaceUtil.ofTopic("test_metalake", "test_catalog", "test_schema"));assertEquals(expectedTopic.id(), convertedTopic.id());assertEquals(expectedTopic.name(), convertedTopic.name());@@ -206,12 +209,12 @@ public class TestPOConverters {CatalogPO catalogPO2 = createCatalogPO(2L, "test2", 1L, "this is test2");List<CatalogPO> catalogPOs = new ArrayList<>(Arrays.asList(catalogPO1, catalogPO2));List<CatalogEntity> convertedCatalogs =- POConverters.fromCatalogPOs(catalogPOs, Namespace.ofCatalog("test_metalake"));+ POConverters.fromCatalogPOs(catalogPOs, NamespaceUtil.ofCatalog("test_metalake"));CatalogEntity expectedCatalog1 =- createCatalog(1L, "test", Namespace.ofCatalog("test_metalake"), "this is test");+ createCatalog(1L, "test", NamespaceUtil.ofCatalog("test_metalake"), "this is test");CatalogEntity expectedCatalog2 =- createCatalog(2L, "test2", Namespace.ofCatalog("test_metalake"), "this is test2");+ createCatalog(2L, "test2", NamespaceUtil.ofCatalog("test_metalake"), "this is test2");List<CatalogEntity> expectedCatalogs =new ArrayList<>(Arrays.asList(expectedCatalog1, expectedCatalog2));@@ -239,14 +242,15 @@ public class TestPOConverters {SchemaPO schemaPO2 = createSchemaPO(2L, "test2", 1L, 1L, "this is test2");List<SchemaPO> schemaPOs = new ArrayList<>(Arrays.asList(schemaPO1, schemaPO2));List<SchemaEntity> convertedSchemas =- POConverters.fromSchemaPOs(schemaPOs, Namespace.ofSchema("test_metalake", "test_catalog"));+ POConverters.fromSchemaPOs(+ schemaPOs, NamespaceUtil.ofSchema("test_metalake", "test_catalog"));SchemaEntity expectedSchema1 =createSchema(- 1L, "test", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test");+ 1L, "test", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test");SchemaEntity expectedSchema2 =createSchema(- 2L, "test2", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test2");+ 2L, "test2", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test2");List<SchemaEntity> expectedSchemas =new ArrayList<>(Arrays.asList(expectedSchema1, expectedSchema2));@@ -271,12 +275,14 @@ public class TestPOConverters {List<TablePO> tablePOs = new ArrayList<>(Arrays.asList(tablePO1, tablePO2));List<TableEntity> convertedTables =POConverters.fromTablePOs(- tablePOs, Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ tablePOs, NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TableEntity expectedTable1 =- createTable(1L, "test", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 1L, "test", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TableEntity expectedTable2 =- createTable(2L, "test2", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 2L, "test2", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));List<TableEntity> expectedTables =new ArrayList<>(Arrays.asList(expectedTable1, expectedTable2));@@ -307,13 +313,13 @@ public class TestPOConverters {List<FilesetPO> filesetPOs = new ArrayList<>(Arrays.asList(filesetPO1, filesetPO2));List<FilesetEntity> convertedFilesets =POConverters.fromFilesetPOs(- filesetPOs, Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"));+ filesetPOs, NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"));FilesetEntity expectedFileset1 =createFileset(1L,"test1",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test1","hdfs://localhost/test1",new HashMap<>());@@ -321,7 +327,7 @@ public class TestPOConverters {createFileset(2L,"test2",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test2","hdfs://localhost/test2",new HashMap<>());@@ -350,20 +356,20 @@ public class TestPOConverters {List<TopicPO> topicPOs = new ArrayList<>(Arrays.asList(topicPO1, topicPO2));List<TopicEntity> convertedTopics =POConverters.fromTopicPOs(- topicPOs, Namespace.ofTopic("test_metalake", "test_catalog", "test_schema"));+ topicPOs, NamespaceUtil.ofTopic("test_metalake", "test_catalog", "test_schema"));TopicEntity expectedTopic1 =createTopic(1L,"test1",- Namespace.ofTopic("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofTopic("test_metalake", "test_catalog", "test_schema"),"test comment1",ImmutableMap.of("key", "value"));TopicEntity expectedTopic2 =createTopic(2L,"test2",- Namespace.ofTopic("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofTopic("test_metalake", "test_catalog", "test_schema"),"test comment2",ImmutableMap.of("key", "value"));List<TopicEntity> expectedTopics =@@ -393,7 +399,7 @@ public class TestPOConverters {@Testpublic void testInitCatalogPOVersion() {CatalogEntity catalog =- createCatalog(1L, "test", Namespace.ofCatalog("test_metalake"), "this is test");+ createCatalog(1L, "test", NamespaceUtil.ofCatalog("test_metalake"), "this is test");CatalogPO initPO = POConverters.initializeCatalogPOWithVersion(catalog, 1L);assertEquals(1, initPO.getCurrentVersion());assertEquals(1, initPO.getLastVersion());@@ -404,7 +410,7 @@ public class TestPOConverters {public void testInitSchemaPOVersion() {SchemaEntity schema =createSchema(- 1L, "test", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test");+ 1L, "test", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test");SchemaPO.Builder builder = SchemaPO.builder().withMetalakeId(1L).withCatalogId(1L);SchemaPO initPO = POConverters.initializeSchemaPOWithVersion(schema, builder);assertEquals(1, initPO.getCurrentVersion());@@ -415,7 +421,8 @@ public class TestPOConverters {@Testpublic void testInitTablePOVersion() {TableEntity tableEntity =- createTable(1L, "test", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 1L, "test", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TablePO.Builder builder =TablePO.builder().withMetalakeId(1L).withCatalogId(1L).withSchemaId(1L);TablePO initPO = POConverters.initializeTablePOWithVersion(tableEntity, builder);@@ -430,7 +437,7 @@ public class TestPOConverters {createFileset(1L,"test",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test","hdfs://localhost/test",new HashMap<>());@@ -459,9 +466,9 @@ public class TestPOConverters {@Testpublic void testUpdateCatalogPOVersion() {CatalogEntity catalog =- createCatalog(1L, "test", Namespace.ofCatalog("test_metalake"), "this is test");+ createCatalog(1L, "test", NamespaceUtil.ofCatalog("test_metalake"), "this is test");CatalogEntity updatedCatalog =- createCatalog(1L, "test", Namespace.ofCatalog("test_metalake"), "this is test2");+ createCatalog(1L, "test", NamespaceUtil.ofCatalog("test_metalake"), "this is test2");CatalogPO initPO = POConverters.initializeCatalogPOWithVersion(catalog, 1L);CatalogPO updatePO = POConverters.updateCatalogPOWithVersion(initPO, updatedCatalog, 1L);assertEquals(1, initPO.getCurrentVersion());@@ -474,10 +481,10 @@ public class TestPOConverters {public void testUpdateSchemaPOVersion() {SchemaEntity schema =createSchema(- 1L, "test", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test");+ 1L, "test", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test");SchemaEntity updatedSchema =createSchema(- 1L, "test", Namespace.ofSchema("test_metalake", "test_catalog"), "this is test2");+ 1L, "test", NamespaceUtil.ofSchema("test_metalake", "test_catalog"), "this is test2");SchemaPO.Builder builder = SchemaPO.builder().withMetalakeId(1L).withCatalogId(1L);SchemaPO initPO = POConverters.initializeSchemaPOWithVersion(schema, builder);SchemaPO updatePO = POConverters.updateSchemaPOWithVersion(initPO, updatedSchema);@@ -490,9 +497,11 @@ public class TestPOConverters {@Testpublic void testUpdateTablePOVersion() {TableEntity tableEntity =- createTable(1L, "test", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 1L, "test", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TableEntity updatedTable =- createTable(1L, "test", Namespace.ofTable("test_metalake", "test_catalog", "test_schema"));+ createTable(+ 1L, "test", NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));TablePO.Builder builder =TablePO.builder().withMetalakeId(1L).withCatalogId(1L).withSchemaId(1L);TablePO initPO = POConverters.initializeTablePOWithVersion(tableEntity, builder);@@ -511,7 +520,7 @@ public class TestPOConverters {createFileset(1L,"test",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test","hdfs://localhost/test",properties);@@ -522,7 +531,7 @@ public class TestPOConverters {createFileset(1L,"test",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test","hdfs://localhost/test",updateProperties);@@ -531,7 +540,7 @@ public class TestPOConverters {createFileset(1L,"test1",- Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),+ NamespaceUtil.ofFileset("test_metalake", "test_catalog", "test_schema"),"this is test","hdfs://localhost/test",properties);diff --git a/core/src/test/java/com/datastrato/gravitino/utils/TestNameIdentifierUtil.java b/core/src/test/java/com/datastrato/gravitino/utils/TestNameIdentifierUtil.javanew file mode 100644index 0000000000..c9be67871f--- /dev/null+++ b/core/src/test/java/com/datastrato/gravitino/utils/TestNameIdentifierUtil.java@@ -0,0 +1,47 @@+/*+ * Copyright 2023 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.utils;++import static org.junit.jupiter.api.Assertions.assertThrows;+import static org.junit.jupiter.api.Assertions.assertTrue;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.exceptions.IllegalNameIdentifierException;+import com.datastrato.gravitino.exceptions.IllegalNamespaceException;+import org.junit.jupiter.api.Test;++public class TestNameIdentifierUtil {++ @Test+ public void testCheckNameIdentifier() {+ NameIdentifier abc = NameIdentifier.of("a", "b", "c");+ NameIdentifier abcd = NameIdentifier.of("a", "b", "c", "d");++ // Test metalake+ assertThrows(+ IllegalNameIdentifierException.class, () -> NameIdentifierUtil.checkMetalake(null));+ Throwable excep =+ assertThrows(IllegalNamespaceException.class, () -> NameIdentifierUtil.checkMetalake(abc));+ assertTrue(excep.getMessage().contains("Metalake namespace must be non-null and empty"));++ // test catalog+ assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifierUtil.checkCatalog(null));+ Throwable excep1 =+ assertThrows(IllegalNamespaceException.class, () -> NameIdentifierUtil.checkCatalog(abc));+ assertTrue(excep1.getMessage().contains("Catalog namespace must be non-null and have 1 level"));++ // test schema+ assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifierUtil.checkSchema(null));+ Throwable excep2 =+ assertThrows(IllegalNamespaceException.class, () -> NameIdentifierUtil.checkSchema(abcd));+ assertTrue(excep2.getMessage().contains("Schema namespace must be non-null and have 2 levels"));++ // test table+ assertThrows(IllegalNameIdentifierException.class, () -> NameIdentifierUtil.checkTable(null));+ Throwable excep3 =+ assertThrows(IllegalNamespaceException.class, () -> NameIdentifierUtil.checkTable(abc));+ assertTrue(excep3.getMessage().contains("Table namespace must be non-null and have 3 levels"));+ }+}diff --git a/core/src/test/java/com/datastrato/gravitino/utils/TestNamespaceUtil.java b/core/src/test/java/com/datastrato/gravitino/utils/TestNamespaceUtil.javanew file mode 100644index 0000000000..938b5e6c16--- /dev/null+++ b/core/src/test/java/com/datastrato/gravitino/utils/TestNamespaceUtil.java@@ -0,0 +1,54 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.utils;++import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.exceptions.IllegalNamespaceException;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.Test;++public class TestNamespaceUtil {++ @Test+ public void testCheckNamespace() {+ Namespace a = Namespace.of("a");+ Namespace ab = Namespace.of("a", "b");+ Namespace abcd = Namespace.of("a", "b", "c", "d");++ // Test metalake+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkMetalake(null));+ Throwable excep =+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkMetalake(ab));+ Assertions.assertTrue(+ excep.getMessage().contains("Metalake namespace must be non-null and empty"));++ // Test catalog+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkCatalog(null));+ Throwable excep1 =+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkCatalog(ab));+ Assertions.assertTrue(+ excep1.getMessage().contains("Catalog namespace must be non-null and have 1 level"));++ // Test schema+ Assertions.assertThrows(IllegalNamespaceException.class, () -> NamespaceUtil.checkSchema(null));+ Throwable excep2 =+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkSchema(a));+ Assertions.assertTrue(+ excep2.getMessage().contains("Schema namespace must be non-null and have 2 levels"));++ // Test table+ Assertions.assertThrows(IllegalNamespaceException.class, () -> NamespaceUtil.checkTable(null));+ Throwable excep3 =+ Assertions.assertThrows(+ IllegalNamespaceException.class, () -> NamespaceUtil.checkTable(abcd));+ Assertions.assertTrue(+ excep3.getMessage().contains("Table namespace must be non-null and have 3 levels"));+ }+}diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.javaindex fa1050341d..481c86c607 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java@@ -104,7 +104,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_create";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -139,7 +139,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_append";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -199,7 +199,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_delete";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -239,7 +239,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_get_status";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -282,7 +282,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_list_status";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -339,7 +339,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_mkdirs";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalog@@ -374,7 +374,7 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {// create filesetString filesetName = "test_fileset_rename";NameIdentifier filesetIdent =- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName);+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName);Catalog catalog = metalake.loadCatalog(catalogName);String storageLocation = genStorageLocation(filesetName);catalogdiff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/store/relational/service/FilesetMetaServiceIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/store/relational/service/FilesetMetaServiceIT.javaindex b3259ae8ed..dd5c625fb1 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/store/relational/service/FilesetMetaServiceIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/store/relational/service/FilesetMetaServiceIT.java@@ -31,6 +31,7 @@ import com.datastrato.gravitino.storage.relational.service.FilesetMetaService;import com.datastrato.gravitino.storage.relational.service.MetalakeMetaService;import com.datastrato.gravitino.storage.relational.service.SchemaMetaService;import com.datastrato.gravitino.storage.relational.session.SqlSessionFactoryHelper;+import com.datastrato.gravitino.utils.NamespaceUtil;import java.io.File;import java.io.IOException;import java.sql.Connection;@@ -116,32 +117,31 @@ public class FilesetMetaServiceIT {BaseMetalake metalake = createBaseMakeLake(idGenerator.nextId(), metalakeName, auditInfo);MetalakeMetaService.getInstance().insertMetalake(metalake, true);assertNotNull(- MetalakeMetaService.getInstance()- .getMetalakeByIdentifier(NameIdentifier.ofMetalake(metalakeName)));+ MetalakeMetaService.getInstance().getMetalakeByIdentifier(NameIdentifier.of(metalakeName)));String catalogName = GravitinoITUtils.genRandomName("tst_fs_catalog");CatalogEntity catalogEntity =createCatalog(- idGenerator.nextId(), Namespace.ofCatalog(metalakeName), catalogName, auditInfo);+ idGenerator.nextId(), NamespaceUtil.ofCatalog(metalakeName), catalogName, auditInfo);CatalogMetaService.getInstance().insertCatalog(catalogEntity, true);assertNotNull(CatalogMetaService.getInstance()- .getCatalogByIdentifier(NameIdentifier.ofCatalog(metalakeName, catalogName)));+ .getCatalogByIdentifier(NameIdentifier.of(metalakeName, catalogName)));String schemaName = GravitinoITUtils.genRandomName("tst_fs_schema");SchemaEntity schemaEntity =createSchemaEntity(idGenerator.nextId(),- Namespace.ofSchema(metalakeName, catalogName),+ NamespaceUtil.ofSchema(metalakeName, catalogName),schemaName,auditInfo);SchemaMetaService.getInstance().insertSchema(schemaEntity, true);assertNotNull(SchemaMetaService.getInstance()- .getSchemaByIdentifier(NameIdentifier.ofSchema(metalakeName, catalogName, schemaName)));+ .getSchemaByIdentifier(NameIdentifier.of(metalakeName, catalogName, schemaName)));String filesetName = GravitinoITUtils.genRandomName("tst_fs_fileset");FilesetEntity filesetEntity =createFilesetEntity(idGenerator.nextId(),- Namespace.ofFileset(metalakeName, catalogName, schemaName),+ NamespaceUtil.ofFileset(metalakeName, catalogName, schemaName),filesetName,auditInfo,"/tmp");@@ -149,10 +149,10 @@ public class FilesetMetaServiceIT {assertNotNull(FilesetMetaService.getInstance().getFilesetByIdentifier(- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName)));+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName)));FilesetMetaService.getInstance().updateFileset(- NameIdentifier.ofFileset(metalakeName, catalogName, schemaName, filesetName),+ NameIdentifier.of(metalakeName, catalogName, schemaName, filesetName),e -> {AuditInfo auditInfo1 =AuditInfo.builder().withCreator("creator5").withCreateTime(Instant.now()).build();diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryITBase.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryITBase.javaindex 4369318983..376f7b7c93 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryITBase.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryITBase.java@@ -7,8 +7,6 @@ package com.datastrato.gravitino.integration.test.trino;import static java.lang.Thread.sleep;import com.datastrato.gravitino.Catalog;-import com.datastrato.gravitino.NameIdentifier;-import com.datastrato.gravitino.Namespace;import com.datastrato.gravitino.SupportsSchemas;import com.datastrato.gravitino.client.GravitinoAdminClient;import com.datastrato.gravitino.client.GravitinoMetalake;@@ -17,6 +15,8 @@ import com.datastrato.gravitino.integration.test.container.ContainerSuite;import com.datastrato.gravitino.integration.test.container.TrinoITContainers;import com.datastrato.gravitino.integration.test.util.AbstractIT;import com.datastrato.gravitino.rel.TableCatalog;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import java.io.File;import java.io.IOException;import java.nio.charset.StandardCharsets;@@ -192,12 +192,12 @@ public class TrinoQueryITBase {TableCatalog tableCatalog = catalog.asTableCatalog();Arrays.stream(tableCatalog.listTables(- Namespace.ofTable(metalakeName, catalogName, schema)))+ NamespaceUtil.ofTable(metalakeName, catalogName, schema))).forEach(table -> {boolean dropped =tableCatalog.dropTable(- NameIdentifier.ofTable(+ NameIdentifierUtil.ofTable(metalakeName, catalogName, schema, table.name()));LOG.info("Drop table \"{}.{}\".{}.{}",diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.javaindex e7b6bbb64b..0af84acab0 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/CatalogOperations.java@@ -20,6 +20,8 @@ import com.datastrato.gravitino.dto.util.DTOConverters;import com.datastrato.gravitino.lock.LockType;import com.datastrato.gravitino.lock.TreeLockUtils;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.Consumes;@@ -67,7 +69,7 @@ public class CatalogOperations {return Utils.doAs(httpRequest,() -> {- Namespace catalogNS = Namespace.ofCatalog(metalake);+ Namespace catalogNS = NamespaceUtil.ofCatalog(metalake);// Lock the root and the metalake with WRITE lock to ensure the consistency of the list.return TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake),@@ -102,10 +104,10 @@ public class CatalogOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofCatalog(metalake, request.getName());+ NameIdentifier ident = NameIdentifierUtil.ofCatalog(metalake, request.getName());Catalog catalog =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofMetalake(metalake),+ NameIdentifierUtil.ofMetalake(metalake),LockType.WRITE,() ->catalogDispatcher.createCatalog(@@ -132,7 +134,7 @@ public class CatalogOperations {@PathParam("metalake") String metalakeName, @PathParam("catalog") String catalogName) {LOG.info("Received load catalog request for catalog: {}.{}", metalakeName, catalogName);try {- NameIdentifier ident = NameIdentifier.ofCatalog(metalakeName, catalogName);+ NameIdentifier ident = NameIdentifierUtil.ofCatalog(metalakeName, catalogName);Catalog catalog =TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> catalogDispatcher.loadCatalog(ident));@@ -159,14 +161,14 @@ public class CatalogOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofCatalog(metalakeName, catalogName);+ NameIdentifier ident = NameIdentifierUtil.ofCatalog(metalakeName, catalogName);CatalogChange[] changes =request.getUpdates().stream().map(CatalogUpdateRequest::catalogChange).toArray(CatalogChange[]::new);Catalog catalog =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofMetalake(metalakeName),+ NameIdentifierUtil.ofMetalake(metalakeName),LockType.WRITE,() -> catalogDispatcher.alterCatalog(ident, changes));Response response = Utils.ok(new CatalogResponse(DTOConverters.toDTO(catalog)));@@ -190,10 +192,10 @@ public class CatalogOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofCatalog(metalakeName, catalogName);+ NameIdentifier ident = NameIdentifierUtil.ofCatalog(metalakeName, catalogName);boolean dropped =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofMetalake(metalakeName),+ NameIdentifierUtil.ofMetalake(metalakeName),LockType.WRITE,() -> catalogDispatcher.dropCatalog(ident));if (!dropped) {diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.javaindex 5345ddee53..6a71c60226 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/FilesetOperations.java@@ -22,6 +22,8 @@ import com.datastrato.gravitino.lock.LockType;import com.datastrato.gravitino.lock.TreeLockUtils;import com.datastrato.gravitino.metrics.MetricNames;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import java.util.Optional;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;@@ -64,7 +66,7 @@ public class FilesetOperations {return Utils.doAs(httpRequest,() -> {- Namespace filesetNS = Namespace.ofFileset(metalake, catalog, schema);+ Namespace filesetNS = NamespaceUtil.ofFileset(metalake, catalog, schema);NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),@@ -106,11 +108,11 @@ public class FilesetOperations {() -> {request.validate();NameIdentifier ident =- NameIdentifier.ofFileset(metalake, catalog, schema, request.getName());+ NameIdentifierUtil.ofFileset(metalake, catalog, schema, request.getName());Fileset fileset =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() ->dispatcher.createFileset(@@ -145,7 +147,7 @@ public class FilesetOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofFileset(metalake, catalog, schema, fileset);+ NameIdentifier ident = NameIdentifierUtil.ofFileset(metalake, catalog, schema, fileset);Fileset t =TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> dispatcher.loadFileset(ident));@@ -175,14 +177,14 @@ public class FilesetOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofFileset(metalake, catalog, schema, fileset);+ NameIdentifier ident = NameIdentifierUtil.ofFileset(metalake, catalog, schema, fileset);FilesetChange[] changes =request.getUpdates().stream().map(FilesetUpdateRequest::filesetChange).toArray(FilesetChange[]::new);Fileset t =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() -> dispatcher.alterFileset(ident, changes));Response response = Utils.ok(new FilesetResponse(DTOConverters.toDTO(t)));@@ -210,10 +212,10 @@ public class FilesetOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofFileset(metalake, catalog, schema, fileset);+ NameIdentifier ident = NameIdentifierUtil.ofFileset(metalake, catalog, schema, fileset);boolean dropped =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() -> dispatcher.dropFileset(ident));if (!dropped) {diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.javaindex 76eb0725a6..581706d34c 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/MetalakeOperations.java@@ -23,6 +23,7 @@ import com.datastrato.gravitino.lock.TreeLockUtils;import com.datastrato.gravitino.metalake.MetalakeDispatcher;import com.datastrato.gravitino.metrics.MetricNames;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;import java.util.Arrays;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;@@ -92,7 +93,7 @@ public class MetalakeOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofMetalake(request.getName());+ NameIdentifier ident = NameIdentifierUtil.ofMetalake(request.getName());Metalake metalake =TreeLockUtils.doWithRootTreeLock(LockType.WRITE,@@ -120,7 +121,7 @@ public class MetalakeOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier identifier = NameIdentifier.ofMetalake(metalakeName);+ NameIdentifier identifier = NameIdentifierUtil.ofMetalake(metalakeName);Metalake metalake =TreeLockUtils.doWithTreeLock(identifier, LockType.READ, () -> metalakeDispatcher.loadMetalake(identifier));@@ -147,7 +148,7 @@ public class MetalakeOperations {httpRequest,() -> {updatesRequest.validate();- NameIdentifier identifier = NameIdentifier.ofMetalake(metalakeName);+ NameIdentifier identifier = NameIdentifierUtil.ofMetalake(metalakeName);MetalakeChange[] changes =updatesRequest.getUpdates().stream().map(MetalakeUpdateRequest::metalakeChange)@@ -177,7 +178,7 @@ public class MetalakeOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier identifier = NameIdentifier.ofMetalake(metalakeName);+ NameIdentifier identifier = NameIdentifierUtil.ofMetalake(metalakeName);boolean dropped =TreeLockUtils.doWithRootTreeLock(LockType.WRITE, () -> metalakeDispatcher.dropMetalake(identifier));diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.javaindex 038603c434..4bdcb1c09c 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/SchemaOperations.java@@ -22,6 +22,8 @@ import com.datastrato.gravitino.lock.LockType;import com.datastrato.gravitino.lock.TreeLockUtils;import com.datastrato.gravitino.metrics.MetricNames;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.Consumes;@@ -67,7 +69,7 @@ public class SchemaOperations {return Utils.doAs(httpRequest,() -> {- Namespace schemaNS = Namespace.ofSchema(metalake, catalog);+ Namespace schemaNS = NamespaceUtil.ofSchema(metalake, catalog);NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog),@@ -96,10 +98,11 @@ public class SchemaOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, request.getName());+ NameIdentifier ident =+ NameIdentifierUtil.ofSchema(metalake, catalog, request.getName());Schema schema =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofCatalog(metalake, catalog),+ NameIdentifierUtil.ofCatalog(metalake, catalog),LockType.WRITE,() ->dispatcher.createSchema(@@ -129,7 +132,7 @@ public class SchemaOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, schema);+ NameIdentifier ident = NameIdentifierUtil.ofSchema(metalake, catalog, schema);Schema s =TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> dispatcher.loadSchema(ident));@@ -159,14 +162,14 @@ public class SchemaOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, schema);+ NameIdentifier ident = NameIdentifierUtil.ofSchema(metalake, catalog, schema);SchemaChange[] changes =request.getUpdates().stream().map(SchemaUpdateRequest::schemaChange).toArray(SchemaChange[]::new);Schema s =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofCatalog(metalake, catalog),+ NameIdentifierUtil.ofCatalog(metalake, catalog),LockType.WRITE,() -> dispatcher.alterSchema(ident, changes));Response response = Utils.ok(new SchemaResponse(DTOConverters.toDTO(s)));@@ -194,10 +197,10 @@ public class SchemaOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofSchema(metalake, catalog, schema);+ NameIdentifier ident = NameIdentifierUtil.ofSchema(metalake, catalog, schema);boolean dropped =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofCatalog(metalake, catalog),+ NameIdentifierUtil.ofCatalog(metalake, catalog),LockType.WRITE,() -> dispatcher.dropSchema(ident, cascade));if (!dropped) {diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.javaindex 5ac9ff4080..b0093fd2b9 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TableOperations.java@@ -25,6 +25,8 @@ import com.datastrato.gravitino.metrics.MetricNames;import com.datastrato.gravitino.rel.Table;import com.datastrato.gravitino.rel.TableChange;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.DELETE;@@ -68,7 +70,7 @@ public class TableOperations {return Utils.doAs(httpRequest,() -> {- Namespace tableNS = Namespace.ofTable(metalake, catalog, schema);+ Namespace tableNS = NamespaceUtil.ofTable(metalake, catalog, schema);NameIdentifier[] idents =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),@@ -102,7 +104,7 @@ public class TableOperations {() -> {request.validate();NameIdentifier ident =- NameIdentifier.ofTable(metalake, catalog, schema, request.getName());+ NameIdentifierUtil.ofTable(metalake, catalog, schema, request.getName());Table table =TreeLockUtils.doWithTreeLock(@@ -145,7 +147,7 @@ public class TableOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofTable(metalake, catalog, schema, table);+ NameIdentifier ident = NameIdentifierUtil.ofTable(metalake, catalog, schema, table);Table t =TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> dispatcher.loadTable(ident));@@ -175,7 +177,7 @@ public class TableOperations {httpRequest,() -> {request.validate();- NameIdentifier ident = NameIdentifier.ofTable(metalake, catalog, schema, table);+ NameIdentifier ident = NameIdentifierUtil.ofTable(metalake, catalog, schema, table);TableChange[] changes =request.getUpdates().stream().map(TableUpdateRequest::tableChange)@@ -217,7 +219,7 @@ public class TableOperations {return Utils.doAs(httpRequest,() -> {- NameIdentifier ident = NameIdentifier.ofTable(metalake, catalog, schema, table);+ NameIdentifier ident = NameIdentifierUtil.ofTable(metalake, catalog, schema, table);boolean dropped =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),diff --git a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.javaindex d12a811e3d..c49552ac8b 100644--- a/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java+++ b/server/src/main/java/com/datastrato/gravitino/server/web/rest/TopicOperations.java@@ -22,6 +22,8 @@ import com.datastrato.gravitino.messaging.Topic;import com.datastrato.gravitino.messaging.TopicChange;import com.datastrato.gravitino.metrics.MetricNames;import com.datastrato.gravitino.server.web.Utils;+import com.datastrato.gravitino.utils.NameIdentifierUtil;+import com.datastrato.gravitino.utils.NamespaceUtil;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.DELETE;@@ -62,7 +64,7 @@ public class TopicOperations {httpRequest,() -> {LOG.info("Listing topics under schema: {}.{}.{}", metalake, catalog, schema);- Namespace topicNS = Namespace.ofTopic(metalake, catalog, schema);+ Namespace topicNS = NamespaceUtil.ofTopic(metalake, catalog, schema);NameIdentifier[] topics =TreeLockUtils.doWithTreeLock(NameIdentifier.of(metalake, catalog, schema),@@ -100,11 +102,11 @@ public class TopicOperations {request.getName());request.validate();NameIdentifier ident =- NameIdentifier.ofTopic(metalake, catalog, schema, request.getName());+ NameIdentifierUtil.ofTopic(metalake, catalog, schema, request.getName());Topic topic =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() ->dispatcher.createTopic(@@ -139,7 +141,7 @@ public class TopicOperations {httpRequest,() -> {LOG.info("Loading topic: {}.{}.{}.{}", metalake, catalog, schema, topic);- NameIdentifier ident = NameIdentifier.ofTopic(metalake, catalog, schema, topic);+ NameIdentifier ident = NameIdentifierUtil.ofTopic(metalake, catalog, schema, topic);Topic t =TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> dispatcher.loadTopic(ident));@@ -170,7 +172,7 @@ public class TopicOperations {() -> {LOG.info("Altering topic: {}.{}.{}.{}", metalake, catalog, schema, topic);request.validate();- NameIdentifier ident = NameIdentifier.ofTopic(metalake, catalog, schema, topic);+ NameIdentifier ident = NameIdentifierUtil.ofTopic(metalake, catalog, schema, topic);TopicChange[] changes =request.getUpdates().stream().map(TopicUpdateRequest::topicChange)@@ -178,7 +180,7 @@ public class TopicOperations {Topic t =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() -> dispatcher.alterTopic(ident, changes));Response response = Utils.ok(new TopicResponse(DTOConverters.toDTO(t)));@@ -206,10 +208,10 @@ public class TopicOperations {httpRequest,() -> {LOG.info("Dropping topic under schema: {}.{}.{}", metalake, catalog, schema);- NameIdentifier ident = NameIdentifier.ofTopic(metalake, catalog, schema, topic);+ NameIdentifier ident = NameIdentifierUtil.ofTopic(metalake, catalog, schema, topic);boolean dropped =TreeLockUtils.doWithTreeLock(- NameIdentifier.ofSchema(metalake, catalog, schema),+ NameIdentifierUtil.ofSchema(metalake, catalog, schema),LockType.WRITE,() -> dispatcher.dropTopic(ident));diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.javaindex e93ee925a8..aef0aa2296 100644--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java@@ -90,7 +90,7 @@ public class CatalogConnectorMetadata {try {Table table =tableCatalog.loadTable(- NameIdentifier.ofTable(metalake.name(), catalogName, schemaName, tableName));+ NameIdentifier.of(metalake.name(), catalogName, schemaName, tableName));return new GravitinoTable(schemaName, tableName, table);} catch (NoSuchTableException e) {throw new TrinoException(GRAVITINO_TABLE_NOT_EXISTS, "Table does not exist", e);@@ -100,7 +100,7 @@ public class CatalogConnectorMetadata {public List<String> listTables(String schemaName) {try {NameIdentifier[] tables =- tableCatalog.listTables(Namespace.ofTable(metalake.name(), catalogName, schemaName));+ tableCatalog.listTables(Namespace.of(metalake.name(), catalogName, schemaName));return Arrays.stream(tables).map(NameIdentifier::name).toList();} catch (NoSuchSchemaException e) {throw new TrinoException(GRAVITINO_SCHEMA_NOT_EXISTS, SCHEMA_DOES_NOT_EXIST_MSG, e);@@ -109,13 +109,12 @@ public class CatalogConnectorMetadata {public boolean tableExists(String schemaName, String tableName) {return tableCatalog.tableExists(- NameIdentifier.ofTable(metalake.name(), catalogName, schemaName, tableName));+ NameIdentifier.of(metalake.name(), catalogName, schemaName, tableName));}public void createTable(GravitinoTable table, boolean ignoreExisting) {NameIdentifier identifier =- NameIdentifier.ofTable(- metalake.name(), catalogName, table.getSchemaName(), table.getName());+ NameIdentifier.of(metalake.name(), catalogName, table.getSchemaName(), table.getName());try {tableCatalog.createTable(identifier,@@ -160,7 +159,7 @@ public class CatalogConnectorMetadata {public void dropTable(SchemaTableName tableName) {boolean dropped =tableCatalog.dropTable(- NameIdentifier.ofTable(+ NameIdentifier.of(metalake.name(), catalogName, tableName.getSchemaName(), tableName.getTableName()));if (!dropped) {throw new TrinoException(GRAVITINO_OPERATION_FAILED, "Failed to drop table " + tableName);@@ -174,7 +173,7 @@ public class CatalogConnectorMetadata {private void applyAlter(SchemaTableName tableName, TableChange... change) {try {tableCatalog.alterTable(- NameIdentifier.ofTable(+ NameIdentifier.of(metalake.name(), catalogName, tableName.getSchemaName(), tableName.getTableName()),change);} catch (NoSuchTableException e) {diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.javaindex c489f62196..141d0e214a 100644--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java@@ -70,7 +70,7 @@ public class GravitinoCatalog {}public NameIdentifier geNameIdentifier() {- return NameIdentifier.ofCatalog(metalake, name);+ return NameIdentifier.of(metalake, name);}public String getProperty(String name, String defaultValue) {diff --git a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/GravitinoMockServer.java b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/GravitinoMockServer.javaindex 78dcb89243..444b2f4736 100644--- a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/GravitinoMockServer.java+++ b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/GravitinoMockServer.java@@ -133,7 +133,7 @@ public class GravitinoMockServer implements AutoCloseable {@Overridepublic NameIdentifier[] answer(InvocationOnMock invocation) throws Throwable {return metalakes.get(metalakeName).catalogs.keySet().stream()- .map(catalogName -> NameIdentifier.ofCatalog(metalakeName, catalogName))+ .map(catalogName -> NameIdentifier.of(metalakeName, catalogName)).toArray(NameIdentifier[]::new);};});@@ -408,7 +408,7 @@ public class GravitinoMockServer implements AutoCloseable {ArrayList<NameIdentifier> tableNames = new ArrayList<>();for (SchemaTableName tableName : metadata.listTables(null, Optional.empty())) {tableNames.add(- NameIdentifier.ofTable(+ NameIdentifier.of(schemaName.level(0),schemaName.level(1),schemaName.level(2),