Skip to content

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

[#3101] fix(all): Only validate the name when creating (#3122)

mchades01cbe1174155
diff --git a/api/src/main/java/com/datastrato/gravitino/exceptions/GravitinoRuntimeException.java b/api/src/main/java/com/datastrato/gravitino/exceptions/GravitinoRuntimeException.java
index 77706ff924..8d0d62fe80 100644
--- a/api/src/main/java/com/datastrato/gravitino/exceptions/GravitinoRuntimeException.java
+++ b/api/src/main/java/com/datastrato/gravitino/exceptions/GravitinoRuntimeException.java
@@ -27,7 +27,7 @@ public class GravitinoRuntimeException extends RuntimeException {
*/
@FormatMethod
public GravitinoRuntimeException(@FormatString String message, Object... args) {
- super(String.format(message, args));
+ super(args.length == 0 ? message : String.format(message, args));
}
/**
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.java
index c9c61cb616..916f7c6183 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
@@ -231,6 +231,17 @@ public class HadoopCatalogIT extends AbstractIT {
"Should throw IllegalArgumentException when storage location is null");
}
+ @Test
+ void testNameSpec() {
+ String illegalName = "/%~?*";
+
+ NameIdentifier nameIdentifier =
+ NameIdentifier.of(metalakeName, catalogName, schemaName, illegalName);
+
+ Assertions.assertThrows(
+ NoSuchFilesetException.class, () -> catalog.asFilesetCatalog().loadFileset(nameIdentifier));
+ }
+
@Test
public void testLoadFileset() throws IOException {
// create fileset
diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
index 649d20b510..bacc2ddf10 100644
--- a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
+++ b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
@@ -1248,6 +1248,47 @@ public class CatalogMysqlIT extends AbstractIT {
"TABLENAME", table_comment, Arrays.asList(newColumns), properties, indexes, table);
}
+ @Test
+ void testNameSpec() {
+ // test operate illegal schema name from MySQL
+ String testSchemaName = "//";
+ String sql = String.format("CREATE DATABASE `%s`", testSchemaName);
+ mysqlService.executeQuery(sql);
+
+ NameIdentifier schemaIdent = NameIdentifier.of(metalakeName, catalogName, testSchemaName);
+ Schema schema = catalog.asSchemas().loadSchema(schemaIdent);
+ Assertions.assertEquals(testSchemaName, schema.name());
+
+ NameIdentifier[] schemaIdents =
+ catalog.asSchemas().listSchemas(Namespace.of(metalakeName, catalogName));
+ Assertions.assertTrue(
+ Arrays.stream(schemaIdents).anyMatch(s -> s.name().equals(testSchemaName)));
+
+ Assertions.assertTrue(catalog.asSchemas().dropSchema(schemaIdent, false));
+ Assertions.assertFalse(catalog.asSchemas().schemaExists(schemaIdent));
+
+ // test operate illegal table name from MySQL
+ mysqlService.executeQuery(sql);
+ String testTableName = "//";
+ sql = String.format("CREATE TABLE `%s`.`%s` (id int)", testSchemaName, testTableName);
+ mysqlService.executeQuery(sql);
+ NameIdentifier tableIdent =
+ NameIdentifier.of(metalakeName, catalogName, testSchemaName, testTableName);
+
+ Table table = catalog.asTableCatalog().loadTable(tableIdent);
+ Assertions.assertEquals(testTableName, table.name());
+
+ NameIdentifier[] tableIdents =
+ catalog
+ .asTableCatalog()
+ .listTables(Namespace.of(metalakeName, catalogName, testSchemaName));
+ Assertions.assertTrue(Arrays.stream(tableIdents).anyMatch(t -> t.name().equals(testTableName)));
+
+ Assertions.assertTrue(catalog.asTableCatalog().dropTable(tableIdent));
+ Assertions.assertFalse(catalog.asTableCatalog().tableExists(tableIdent));
+ Assertions.assertFalse(catalog.asTableCatalog().purgeTable(tableIdent));
+ }
+
@Test
void testMySQLSchemaNameCaseSensitive() {
Column col1 = Column.of("col_1", Types.LongType.get(), "id", false, false, null);
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.java
index e7854705b8..2636f2c236 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
@@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.time.Duration;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -358,6 +359,37 @@ public class CatalogKafkaIT extends AbstractIT {
"Topic should not exist after dropping");
}
+ @Test
+ public void testNameSpec() throws ExecutionException, InterruptedException {
+ // create topic in Kafka with special characters
+ String illegalName = "test.topic";
+ adminClient.createTopics(ImmutableList.of(new NewTopic(illegalName, 1, (short) 1))).all().get();
+
+ NameIdentifier ident =
+ NameIdentifier.of(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME, illegalName);
+ IllegalArgumentException exception =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ catalog
+ .asTopicCatalog()
+ .createTopic(ident, "comment", null, Collections.emptyMap()));
+ Assertions.assertTrue(exception.getMessage().contains("Illegal name: test.topic"));
+
+ Topic loadedTopic = catalog.asTopicCatalog().loadTopic(ident);
+ Assertions.assertEquals(illegalName, loadedTopic.name());
+
+ NameIdentifier[] topics =
+ catalog
+ .asTopicCatalog()
+ .listTopics(Namespace.ofTopic(METALAKE_NAME, CATALOG_NAME, DEFAULT_SCHEMA_NAME));
+ Assertions.assertTrue(
+ Arrays.stream(topics).anyMatch(topic -> topic.name().equals(illegalName)));
+
+ Assertions.assertTrue(catalog.asTopicCatalog().dropTopic(ident));
+ Assertions.assertFalse(catalog.asTopicCatalog().topicExists(ident));
+ }
+
private void assertTopicWithKafka(Topic createdTopic)
throws ExecutionException, InterruptedException {
// get topic from Kafka directly
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.java
index a6c839c082..c31d73deea 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
@@ -21,6 +21,7 @@ import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;
import com.datastrato.gravitino.rel.Schema;
import com.datastrato.gravitino.rel.SchemaChange;
import com.datastrato.gravitino.rel.SupportsSchemas;
+import com.datastrato.gravitino.rest.RESTUtils;
import com.google.common.annotations.VisibleForTesting;
import java.util.Arrays;
import java.util.Collections;
@@ -95,7 +96,8 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements SupportsSchemas {
throws NoSuchCatalogException, SchemaAlreadyExistsException {
NameIdentifier.checkSchema(ident);
- SchemaCreateRequest req = new SchemaCreateRequest(ident.name(), comment, properties);
+ SchemaCreateRequest req =
+ new SchemaCreateRequest(RESTUtils.encodeString(ident.name()), comment, properties);
req.validate();
SchemaResponse resp =
@@ -123,7 +125,7 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements SupportsSchemas {
SchemaResponse resp =
restClient.get(
- formatSchemaRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatSchemaRequestPath(ident.namespace()) + "/" + RESTUtils.encodeString(ident.name()),
SchemaResponse.class,
Collections.emptyMap(),
ErrorHandlers.schemaErrorHandler());
@@ -154,7 +156,7 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements SupportsSchemas {
SchemaResponse resp =
restClient.put(
- formatSchemaRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatSchemaRequestPath(ident.namespace()) + "/" + RESTUtils.encodeString(ident.name()),
updatesRequest,
SchemaResponse.class,
Collections.emptyMap(),
@@ -179,7 +181,9 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements SupportsSchemas {
try {
DropResponse resp =
restClient.delete(
- formatSchemaRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatSchemaRequestPath(ident.namespace())
+ + "/"
+ + RESTUtils.encodeString(ident.name()),
Collections.singletonMap("cascade", String.valueOf(cascade)),
DropResponse.class,
Collections.emptyMap(),
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.java
index ff95b79e08..027aac6a16 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
@@ -19,6 +19,7 @@ import com.datastrato.gravitino.exceptions.NoSuchFilesetException;
import com.datastrato.gravitino.exceptions.NoSuchSchemaException;
import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.file.FilesetChange;
+import com.datastrato.gravitino.rest.RESTUtils;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.util.Arrays;
@@ -88,7 +89,9 @@ public class FilesetCatalog extends BaseSchemaCatalog
FilesetResponse resp =
restClient.get(
- formatFilesetRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatFilesetRequestPath(ident.namespace())
+ + "/"
+ + RESTUtils.encodeString(ident.name()),
FilesetResponse.class,
Collections.emptyMap(),
ErrorHandlers.filesetErrorHandler());
@@ -126,7 +129,7 @@ public class FilesetCatalog extends BaseSchemaCatalog
FilesetCreateRequest req =
FilesetCreateRequest.builder()
- .name(ident.name())
+ .name(RESTUtils.encodeString(ident.name()))
.comment(comment)
.type(type)
.storageLocation(storageLocation)
@@ -208,7 +211,7 @@ public class FilesetCatalog extends BaseSchemaCatalog
return new StringBuilder()
.append(formatSchemaRequestPath(schemaNs))
.append("/")
- .append(ns.level(2))
+ .append(RESTUtils.encodeString(ns.level(2)))
.append("/filesets")
.toString();
}
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.java
index 5d8287cbc2..3f4c48d6aa 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
@@ -28,6 +28,7 @@ import com.datastrato.gravitino.rel.expressions.distributions.Distribution;
import com.datastrato.gravitino.rel.expressions.sorts.SortOrder;
import com.datastrato.gravitino.rel.expressions.transforms.Transform;
import com.datastrato.gravitino.rel.indexes.Index;
+import com.datastrato.gravitino.rest.RESTUtils;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.util.Arrays;
@@ -100,7 +101,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
TableResponse resp =
restClient.get(
- formatTableRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatTableRequestPath(ident.namespace()) + "/" + RESTUtils.encodeString(ident.name()),
TableResponse.class,
Collections.emptyMap(),
ErrorHandlers.tableErrorHandler());
@@ -137,7 +138,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
TableCreateRequest req =
new TableCreateRequest(
- ident.name(),
+ RESTUtils.encodeString(ident.name()),
comment,
toDTOs(columns),
properties,
@@ -182,7 +183,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
TableResponse resp =
restClient.put(
- formatTableRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatTableRequestPath(ident.namespace()) + "/" + RESTUtils.encodeString(ident.name()),
updatesRequest,
TableResponse.class,
Collections.emptyMap(),
@@ -205,7 +206,9 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
try {
DropResponse resp =
restClient.delete(
- formatTableRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatTableRequestPath(ident.namespace())
+ + "/"
+ + RESTUtils.encodeString(ident.name()),
DropResponse.class,
Collections.emptyMap(),
ErrorHandlers.tableErrorHandler());
@@ -233,7 +236,9 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
try {
DropResponse resp =
restClient.delete(
- formatTableRequestPath(ident.namespace()) + "/" + ident.name(),
+ formatTableRequestPath(ident.namespace())
+ + "/"
+ + RESTUtils.encodeString(ident.name()),
params,
DropResponse.class,
Collections.emptyMap(),
@@ -255,7 +260,7 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
return new StringBuilder()
.append(formatSchemaRequestPath(schemaNs))
.append("/")
- .append(ns.level(2))
+ .append(RESTUtils.encodeString(ns.level(2)))
.append("/tables")
.toString();
}
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CapabilityHelpers.java b/core/src/main/java/com/datastrato/gravitino/catalog/CapabilityHelpers.java
index 2ed2aca6e4..285fc1a5e0 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/CapabilityHelpers.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CapabilityHelpers.java
@@ -79,6 +79,37 @@ public class CapabilityHelpers {
return NameIdentifier.of(namespace, name);
}
+ public static NameIdentifier[] applyCaseSensitive(
+ NameIdentifier[] idents, Capability.Scope scope, OperationDispatcher operationDispatcher) {
+ return Arrays.stream(idents)
+ .map(ident -> applyCaseSensitive(ident, scope, operationDispatcher))
+ .toArray(NameIdentifier[]::new);
+ }
+
+ public static NameIdentifier applyCaseSensitive(
+ NameIdentifier ident, Capability.Scope scope, OperationDispatcher operationDispatcher) {
+ Capability capabilities = operationDispatcher.getCatalogCapability(ident);
+ Namespace namespace = applyCaseSensitive(ident.namespace(), scope, operationDispatcher);
+
+ String name = applyCaseSensitiveOnName(scope, ident.name(), capabilities);
+ return NameIdentifier.of(namespace, name);
+ }
+
+ public static Namespace applyCaseSensitive(
+ Namespace namespace, Capability.Scope identScope, OperationDispatcher operationDispatcher) {
+ String metalake = namespace.level(0);
+ String catalog = namespace.level(1);
+ if (identScope == Capability.Scope.TABLE
+ || identScope == Capability.Scope.FILESET
+ || identScope == Capability.Scope.TOPIC) {
+ String schema = namespace.level(namespace.length() - 1);
+ Capability capabilities = operationDispatcher.getCatalogCapability(namespace);
+ schema = applyCaseSensitiveOnName(Capability.Scope.SCHEMA, schema, capabilities);
+ return Namespace.of(metalake, catalog, schema);
+ }
+ return namespace;
+ }
+
public static Transform[] applyCapabilities(Transform[] transforms, Capability capabilities) {
return Arrays.stream(transforms)
.map(t -> applyCapabilities(t, capabilities))
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/FilesetNormalizeDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/FilesetNormalizeDispatcher.java
index d89871cbaa..6dd66565cb 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/FilesetNormalizeDispatcher.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/FilesetNormalizeDispatcher.java
@@ -5,6 +5,7 @@
package com.datastrato.gravitino.catalog;
import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCapabilities;
+import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCaseSensitive;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
@@ -26,21 +27,26 @@ public class FilesetNormalizeDispatcher implements FilesetDispatcher {
@Override
public NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException {
- Capability capability = dispatcher.getCatalogCapability(namespace);
- Namespace standardizedNamespace =
- applyCapabilities(namespace, Capability.Scope.FILESET, capability);
- NameIdentifier[] identifiers = dispatcher.listFilesets(standardizedNamespace);
- return applyCapabilities(identifiers, Capability.Scope.FILESET, capability);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ Namespace caseSensitiveNs = applyCaseSensitive(namespace, Capability.Scope.FILESET, dispatcher);
+ NameIdentifier[] identifiers = dispatcher.listFilesets(caseSensitiveNs);
+ return applyCaseSensitive(identifiers, Capability.Scope.FILESET, dispatcher);
}
@Override
public Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {
- return dispatcher.loadFileset(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.loadFileset(applyCaseSensitive(ident, Capability.Scope.FILESET, dispatcher));
}
@Override
public boolean filesetExists(NameIdentifier ident) {
- return dispatcher.filesetExists(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.filesetExists(
+ applyCaseSensitive(ident, Capability.Scope.FILESET, dispatcher));
}
@Override
@@ -60,13 +66,17 @@ public class FilesetNormalizeDispatcher implements FilesetDispatcher {
throws NoSuchFilesetException, IllegalArgumentException {
Capability capability = dispatcher.getCatalogCapability(ident);
return dispatcher.alterFileset(
- applyCapabilities(ident, Capability.Scope.FILESET, capability),
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ applyCaseSensitive(ident, Capability.Scope.FILESET, dispatcher),
applyCapabilities(capability, changes));
}
@Override
public boolean dropFileset(NameIdentifier ident) {
- return dispatcher.dropFileset(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.dropFileset(applyCaseSensitive(ident, Capability.Scope.FILESET, dispatcher));
}
private NameIdentifier normalizeNameIdentifier(NameIdentifier ident) {
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaNormalizeDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaNormalizeDispatcher.java
index 22da2a0160..e1f9e613eb 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/SchemaNormalizeDispatcher.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SchemaNormalizeDispatcher.java
@@ -5,6 +5,7 @@
package com.datastrato.gravitino.catalog;
import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCapabilities;
+import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCaseSensitive;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
@@ -27,16 +28,17 @@ public class SchemaNormalizeDispatcher implements SchemaDispatcher {
@Override
public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {
- Capability capability = dispatcher.getCatalogCapability(namespace);
- Namespace standardizedNamespace =
- applyCapabilities(namespace, Capability.Scope.SCHEMA, capability);
- NameIdentifier[] identifiers = dispatcher.listSchemas(standardizedNamespace);
- return applyCapabilities(identifiers, Capability.Scope.SCHEMA, capability);
+ NameIdentifier[] identifiers = dispatcher.listSchemas(namespace);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return applyCaseSensitive(identifiers, Capability.Scope.SCHEMA, dispatcher);
}
@Override
public boolean schemaExists(NameIdentifier ident) {
- return dispatcher.schemaExists(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.schemaExists(applyCaseSensitive(ident, Capability.Scope.SCHEMA, dispatcher));
}
@Override
@@ -47,18 +49,26 @@ public class SchemaNormalizeDispatcher implements SchemaDispatcher {
@Override
public Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {
- return dispatcher.loadSchema(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.loadSchema(applyCaseSensitive(ident, Capability.Scope.SCHEMA, dispatcher));
}
@Override
public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
throws NoSuchSchemaException {
- return dispatcher.alterSchema(normalizeNameIdentifier(ident), changes);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.alterSchema(
+ applyCaseSensitive(ident, Capability.Scope.SCHEMA, dispatcher), changes);
}
@Override
public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {
- return dispatcher.dropSchema(normalizeNameIdentifier(ident), cascade);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.dropSchema(
+ applyCaseSensitive(ident, Capability.Scope.SCHEMA, dispatcher), cascade);
}
private NameIdentifier normalizeNameIdentifier(NameIdentifier ident) {
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TableNormalizeDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TableNormalizeDispatcher.java
index 68784272e7..ac7da6cbc5 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/TableNormalizeDispatcher.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TableNormalizeDispatcher.java
@@ -5,6 +5,7 @@
package com.datastrato.gravitino.catalog;
import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCapabilities;
+import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCaseSensitive;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
@@ -31,16 +32,18 @@ public class TableNormalizeDispatcher implements TableDispatcher {
@Override
public NameIdentifier[] listTables(Namespace namespace) throws NoSuchSchemaException {
- Capability capability = dispatcher.getCatalogCapability(namespace);
- Namespace standardizedNamespace =
- applyCapabilities(namespace, Capability.Scope.TABLE, capability);
- NameIdentifier[] identifiers = dispatcher.listTables(standardizedNamespace);
- return applyCapabilities(identifiers, Capability.Scope.TABLE, capability);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ Namespace caseSensitiveNs = applyCaseSensitive(namespace, Capability.Scope.TABLE, dispatcher);
+ NameIdentifier[] identifiers = dispatcher.listTables(caseSensitiveNs);
+ return applyCaseSensitive(identifiers, Capability.Scope.TABLE, dispatcher);
}
@Override
public Table loadTable(NameIdentifier ident) throws NoSuchTableException {
- return dispatcher.loadTable(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.loadTable(applyCaseSensitive(ident, Capability.Scope.TABLE, dispatcher));
}
@Override
@@ -71,13 +74,17 @@ public class TableNormalizeDispatcher implements TableDispatcher {
throws NoSuchTableException, IllegalArgumentException {
Capability capability = dispatcher.getCatalogCapability(ident);
return dispatcher.alterTable(
- applyCapabilities(ident, Capability.Scope.TABLE, capability),
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ applyCaseSensitive(ident, Capability.Scope.TABLE, dispatcher),
applyCapabilities(capability, changes));
}
@Override
public boolean dropTable(NameIdentifier ident) {
- return dispatcher.dropTable(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.dropTable(applyCaseSensitive(ident, Capability.Scope.TABLE, dispatcher));
}
@Override
@@ -87,7 +94,9 @@ public class TableNormalizeDispatcher implements TableDispatcher {
@Override
public boolean tableExists(NameIdentifier ident) {
- return dispatcher.tableExists(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.tableExists(applyCaseSensitive(ident, Capability.Scope.TABLE, dispatcher));
}
private NameIdentifier normalizeNameIdentifier(NameIdentifier ident) {
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/TopicNormalizeDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/TopicNormalizeDispatcher.java
index 753a2f0185..aa372b623c 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/TopicNormalizeDispatcher.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/TopicNormalizeDispatcher.java
@@ -5,6 +5,7 @@
package com.datastrato.gravitino.catalog;
import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCapabilities;
+import static com.datastrato.gravitino.catalog.CapabilityHelpers.applyCaseSensitive;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
@@ -27,21 +28,25 @@ public class TopicNormalizeDispatcher implements TopicDispatcher {
@Override
public NameIdentifier[] listTopics(Namespace namespace) throws NoSuchSchemaException {
- Capability capability = dispatcher.getCatalogCapability(namespace);
- Namespace standardizedNamespace =
- applyCapabilities(namespace, Capability.Scope.TOPIC, capability);
- NameIdentifier[] identifiers = dispatcher.listTopics(standardizedNamespace);
- return applyCapabilities(identifiers, Capability.Scope.TOPIC, capability);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ Namespace caseSensitiveNs = applyCaseSensitive(namespace, Capability.Scope.TOPIC, dispatcher);
+ NameIdentifier[] identifiers = dispatcher.listTopics(caseSensitiveNs);
+ return applyCaseSensitive(identifiers, Capability.Scope.TOPIC, dispatcher);
}
@Override
public Topic loadTopic(NameIdentifier ident) throws NoSuchTopicException {
- return dispatcher.loadTopic(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.loadTopic(applyCaseSensitive(ident, Capability.Scope.TOPIC, dispatcher));
}
@Override
public boolean topicExists(NameIdentifier ident) {
- return dispatcher.topicExists(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.topicExists(applyCaseSensitive(ident, Capability.Scope.TOPIC, dispatcher));
}
@Override
@@ -54,12 +59,17 @@ public class TopicNormalizeDispatcher implements TopicDispatcher {
@Override
public Topic alterTopic(NameIdentifier ident, TopicChange... changes)
throws NoSuchTopicException, IllegalArgumentException {
- return dispatcher.alterTopic(normalizeNameIdentifier(ident), changes);
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.alterTopic(
+ applyCaseSensitive(ident, Capability.Scope.TOPIC, dispatcher), changes);
}
@Override
public boolean dropTopic(NameIdentifier ident) {
- return dispatcher.dropTopic(normalizeNameIdentifier(ident));
+ // The constraints of the name spec may be more strict than underlying catalog,
+ // and for compatibility reasons, we only apply case-sensitive capabilities here.
+ return dispatcher.dropTopic(applyCaseSensitive(ident, Capability.Scope.TOPIC, dispatcher));
}
private NameIdentifier normalizeNameIdentifier(NameIdentifier ident) {