World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#582] improvement(core): support schema property metadata (#583)
mchadesf539ba868443
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.javaindex 0e916ac165..94355370db 100644--- a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java@@ -78,6 +78,8 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemasprivate HiveCatalogPropertiesMeta catalogPropertiesMetadata;+ private HiveSchemaPropertiesMetadata schemaPropertiesMetadata;+// Map that maintains the mapping of keys in Gravitino to that in Hive, for example, users// will only need to set the configuration 'METASTORE_URL' in Gravitino and Gravitino will change// it to `METASTOREURIS` automatically and pass it to Hive.@@ -103,6 +105,7 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemaspublic void initialize(Map<String, String> conf) throws RuntimeException {this.tablePropertiesMetadata = new HiveTablePropertiesMetadata();this.catalogPropertiesMetadata = new HiveCatalogPropertiesMeta();+ this.schemaPropertiesMetadata = new HiveSchemaPropertiesMetadata();// Key format like gravitino.bypass.a.bMap<String, String> byPassConfig = Maps.newHashMap();@@ -912,4 +915,9 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemaspublic PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {return catalogPropertiesMetadata;}++ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ return schemaPropertiesMetadata;+ }}diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveSchemaPropertiesMetadata.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveSchemaPropertiesMetadata.javanew file mode 100644index 0000000000..346e153198--- /dev/null+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveSchemaPropertiesMetadata.java@@ -0,0 +1,20 @@+/*+ * Copyright 2023 Datastrato.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.catalog.hive;++import com.datastrato.gravitino.catalog.BasePropertiesMetadata;+import com.datastrato.gravitino.catalog.PropertyEntry;+import com.google.common.collect.Maps;+import java.util.Map;++public class HiveSchemaPropertiesMetadata extends BasePropertiesMetadata {+ private static final Map<String, PropertyEntry<?>> propertiesMetadata = Maps.newHashMap();++ @Override+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {+ // TODO(minghuang): support Hive schema properties metadata+ return propertiesMetadata;+ }+}diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.javaindex 432ab69b0e..791e20380a 100644--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java@@ -67,6 +67,8 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsScheprivate IcebergTablePropertiesMetadata icebergTablePropertiesMetadata;+ private IcebergSchemaPropertiesMetadata icebergSchemaPropertiesMetadata;+private final CatalogEntity entity;private IcebergTableOpsHelper icebergTableOpsHelper;@@ -105,6 +107,7 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSchethis.icebergTableOps = new IcebergTableOps(icebergConfig);this.icebergTableOpsHelper = icebergTableOps.createIcebergTableOpsHelper();this.icebergTablePropertiesMetadata = new IcebergTablePropertiesMetadata();+ this.icebergSchemaPropertiesMetadata = new IcebergSchemaPropertiesMetadata();}/** Closes the Iceberg catalog and releases the associated client pool. */@@ -564,4 +567,9 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSchepublic PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {return icebergCatalogPropertiesMetadata;}++ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ return icebergSchemaPropertiesMetadata;+ }}diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergSchemaPropertiesMetadata.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergSchemaPropertiesMetadata.javanew file mode 100644index 0000000000..19471e4422--- /dev/null+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergSchemaPropertiesMetadata.java@@ -0,0 +1,20 @@+/*+ * Copyright 2023 Datastrato.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.catalog.lakehouse.iceberg;++import com.datastrato.gravitino.catalog.BasePropertiesMetadata;+import com.datastrato.gravitino.catalog.PropertyEntry;+import com.google.common.collect.Maps;+import java.util.Map;++public class IcebergSchemaPropertiesMetadata extends BasePropertiesMetadata {+ private static final Map<String, PropertyEntry<?>> propertiesMetadata = Maps.newHashMap();++ @Override+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {+ // TODO: support Iceberg schema properties metadata+ return propertiesMetadata;+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/BaseCatalog.java b/core/src/main/java/com/datastrato/gravitino/catalog/BaseCatalog.javaindex 58f2683016..86bc40530d 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/BaseCatalog.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/BaseCatalog.java@@ -64,6 +64,11 @@ public abstract class BaseCatalog<T extends BaseCatalog>return ops().catalogPropertiesMetadata();}+ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ return ops().schemaPropertiesMetadata();+ }+/*** Retrieves the CatalogOperations instance associated with this catalog. Lazily initializes the* instance if not already created.diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.javaindex 420c743910..9eff8c9c33 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java@@ -110,6 +110,16 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas@Overridepublic Schema createSchema(NameIdentifier ident, String comment, Map<String, String> metadata)throws NoSuchCatalogException, SchemaAlreadyExistsException {+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ doWithCatalog(+ catalogIdent,+ c ->+ c.doWithPropertiesMeta(+ p -> {+ p.schemaPropertiesMetadata().validatePropertyForCreate(metadata);+ return null;+ }),+ IllegalArgumentException.class);long uid = idGenerator.nextId();// Add StringIdentifier to the properties, the specific catalog will handle this// StringIdentifier to make sure only when the operation is successful, the related@@ -117,12 +127,18 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasStringIdentifier stringId = StringIdentifier.fromId(uid);Map<String, String> updatedProperties = StringIdentifier.addToProperties(stringId, metadata);+ doWithCatalog(+ catalogIdent,+ c -> c.doWithSchemaOps(s -> s.createSchema(ident, comment, updatedProperties)),+ NoSuchCatalogException.class,+ SchemaAlreadyExistsException.class);++ // Retrieve the Schema again to obtain some values generated by underlying catalogSchema schema =doWithCatalog(- getCatalogIdentifier(ident),- c -> c.doWithSchemaOps(s -> s.createSchema(ident, comment, updatedProperties)),- NoSuchCatalogException.class,- SchemaAlreadyExistsException.class);+ catalogIdent,+ c -> c.doWithSchemaOps(s -> s.loadSchema(ident)),+ NoSuchSchemaException.class);SchemaEntity schemaEntity =new SchemaEntity.Builder()@@ -141,11 +157,13 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasstore.put(schemaEntity, true /* overwrite */);} catch (Exception e) {LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "put", ident, e);- return EntityCombinedSchema.of(schema);+ return EntityCombinedSchema.of(schema)+ .withHiddenPropertiesSet(getHiddenSchemaPropertyNames(catalogIdent, schema.properties()));}// Merge both the metadata from catalog operation and the metadata from entity store.- return EntityCombinedSchema.of(schema, schemaEntity);+ return EntityCombinedSchema.of(schema, schemaEntity)+ .withHiddenPropertiesSet(getHiddenTablePropertyNames(catalogIdent, schema.properties()));}/**@@ -157,16 +175,19 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas*/@Overridepublic Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {+ NameIdentifier catalogIdentifier = getCatalogIdentifier(ident);Schema schema =doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdentifier,c -> c.doWithSchemaOps(s -> s.loadSchema(ident)),NoSuchSchemaException.class);StringIdentifier stringId = getStringIdFromProperties(schema.properties());// Case 1: The schema is not created by Gravitino.if (stringId == null) {- return EntityCombinedSchema.of(schema);+ return EntityCombinedSchema.of(schema)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdentifier, schema.properties()));}SchemaEntity schemaEntity =@@ -175,7 +196,9 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasidentifier -> store.get(identifier, SCHEMA, SchemaEntity.class),"GET",stringId.id());- return EntityCombinedSchema.of(schema, schemaEntity);+ return EntityCombinedSchema.of(schema, schemaEntity)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdentifier, schema.properties()));}/**@@ -190,16 +213,32 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas@Overridepublic Schema alterSchema(NameIdentifier ident, SchemaChange... changes)throws NoSuchSchemaException {- Schema alteredSchema =+ validateAlterSchemaProperties(ident, changes);++ NameIdentifier catalogIdent = getCatalogIdentifier(ident);+ Schema tempAlteredSchema =doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c -> c.doWithSchemaOps(s -> s.alterSchema(ident, changes)),NoSuchSchemaException.class);+ // Retrieve the Schema again to obtain some values generated by underlying catalog+ Schema alteredSchema =+ doWithCatalog(+ catalogIdent,+ c ->+ c.doWithSchemaOps(+ s ->+ s.loadSchema(+ NameIdentifier.of(ident.namespace(), tempAlteredSchema.name()))),+ NoSuchSchemaException.class);+StringIdentifier stringId = getStringIdFromProperties(alteredSchema.properties());// Case 1: The schema is not created by Gravitino.if (stringId == null) {- return EntityCombinedSchema.of(alteredSchema);+ return EntityCombinedSchema.of(alteredSchema)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdent, alteredSchema.properties()));}SchemaEntity updatedSchemaEntity =@@ -227,7 +266,9 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas.build()),"UPDATE",stringId.id());- return EntityCombinedSchema.of(alteredSchema, updatedSchemaEntity);+ return EntityCombinedSchema.of(alteredSchema, updatedSchemaEntity)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdent, alteredSchema.properties()));}/**@@ -294,8 +335,9 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasStringIdentifier stringId = getStringIdFromProperties(table.properties());// Case 1: The table is not created by Gravitino.if (stringId == null) {- return EntityCombinedTable.of(table, null)- .withHiddenPropertiesSet(getHiddenPropertyNames(catalogIdentifier, table.properties()));+ return EntityCombinedTable.of(table)+ .withHiddenPropertiesSet(+ getHiddenTablePropertyNames(catalogIdentifier, table.properties()));}TableEntity tableEntity =@@ -306,10 +348,11 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasstringId.id());return EntityCombinedTable.of(table, tableEntity)- .withHiddenPropertiesSet(getHiddenPropertyNames(catalogIdentifier, table.properties()));+ .withHiddenPropertiesSet(+ getHiddenTablePropertyNames(catalogIdentifier, table.properties()));}- private Set<String> getHiddenPropertyNames(+ private Set<String> getHiddenTablePropertyNames(NameIdentifier catalogIdent, Map<String, String> properties) {return doWithCatalog(catalogIdent,@@ -324,6 +367,21 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasIllegalArgumentException.class);}+ private Set<String> getHiddenSchemaPropertyNames(+ NameIdentifier catalogIdent, Map<String, String> properties) {+ return doWithCatalog(+ catalogIdent,+ c ->+ c.doWithPropertiesMeta(+ p -> {+ PropertiesMetadata propertiesMetadata = p.schemaPropertiesMetadata();+ return properties.keySet().stream()+ .filter(propertiesMetadata::isHiddenProperty)+ .collect(Collectors.toSet());+ }),+ IllegalArgumentException.class);+ }+/*** Creates a new table in a schema.*@@ -346,8 +404,9 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasDistribution distribution,SortOrder[] sortOrders)throws NoSuchSchemaException, TableAlreadyExistsException {+ NameIdentifier catalogIdent = getCatalogIdentifier(ident);doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c ->c.doWithPropertiesMeta(p -> {@@ -363,7 +422,7 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasMap<String, String> updatedProperties = StringIdentifier.addToProperties(stringId, properties);doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c ->c.doWithTableOps(t ->@@ -381,7 +440,7 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas// Retrieve the Table again to obtain some values generated by underlying catalogTable table =doWithCatalog(- getCatalogIdentifier(ident),+ catalogIdent,c -> c.doWithTableOps(t -> t.loadTable(ident)),NoSuchTableException.class);@@ -401,14 +460,12 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasstore.put(tableEntity, true /* overwrite */);} catch (Exception e) {LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "put", ident, e);- return EntityCombinedTable.of(table, null)- .withHiddenPropertiesSet(- getHiddenPropertyNames(getCatalogIdentifier(ident), table.properties()));+ return EntityCombinedTable.of(table)+ .withHiddenPropertiesSet(getHiddenTablePropertyNames(catalogIdent, table.properties()));}return EntityCombinedTable.of(table, tableEntity)- .withHiddenPropertiesSet(- getHiddenPropertyNames(getCatalogIdentifier(ident), table.properties()));+ .withHiddenPropertiesSet(getHiddenTablePropertyNames(catalogIdent, table.properties()));}/**@@ -447,9 +504,9 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasStringIdentifier stringId = getStringIdFromProperties(alteredTable.properties());// Case 1: The table is not created by Gravitino.if (stringId == null) {- return EntityCombinedTable.of(alteredTable, null)+ return EntityCombinedTable.of(alteredTable).withHiddenPropertiesSet(- getHiddenPropertyNames(getCatalogIdentifier(ident), alteredTable.properties()));+ getHiddenTablePropertyNames(getCatalogIdentifier(ident), alteredTable.properties()));}TableEntity updatedTableEntity =@@ -489,7 +546,7 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasreturn EntityCombinedTable.of(alteredTable, updatedTableEntity).withHiddenPropertiesSet(- getHiddenPropertyNames(getCatalogIdentifier(ident), alteredTable.properties()));+ getHiddenTablePropertyNames(getCatalogIdentifier(ident), alteredTable.properties()));}private Pair<Map<String, String>, Map<String, String>> getTableAlterProperty(@@ -512,6 +569,27 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasreturn Pair.of(upserts, deletes);}+ private Pair<Map<String, String>, Map<String, String>> getSchemaAlterProperty(+ SchemaChange... schemaChanges) {+ Map<String, String> upserts = Maps.newHashMap();+ Map<String, String> deletes = Maps.newHashMap();++ Arrays.stream(schemaChanges)+ .forEach(+ schemaChange -> {+ if (schemaChange instanceof SchemaChange.SetProperty) {+ SchemaChange.SetProperty setProperty = (SchemaChange.SetProperty) schemaChange;+ upserts.put(setProperty.getProperty(), setProperty.getValue());+ } else if (schemaChange instanceof SchemaChange.RemoveProperty) {+ SchemaChange.RemoveProperty removeProperty =+ (SchemaChange.RemoveProperty) schemaChange;+ deletes.put(removeProperty.getProperty(), removeProperty.getProperty());+ }+ });++ return Pair.of(upserts, deletes);+ }+private void validateAlterTableProperties(NameIdentifier ident, TableChange... changes) {doWithCatalog(getCatalogIdentifier(ident),@@ -527,6 +605,21 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasIllegalArgumentException.class);}+ private void validateAlterSchemaProperties(NameIdentifier ident, SchemaChange... changes) {+ doWithCatalog(+ getCatalogIdentifier(ident),+ c ->+ c.doWithPropertiesMeta(+ p -> {+ Pair<Map<String, String>, Map<String, String>> alterProperty =+ getSchemaAlterProperty(changes);+ p.schemaPropertiesMetadata()+ .validatePropertyForAlter(alterProperty.getLeft(), alterProperty.getRight());+ return null;+ }),+ IllegalArgumentException.class);+ }+/*** Drops a table from the catalog.*diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/HasPropertyMetadata.java b/core/src/main/java/com/datastrato/gravitino/catalog/HasPropertyMetadata.javaindex 67f291523e..502c2b877e 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/HasPropertyMetadata.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/HasPropertyMetadata.java@@ -22,4 +22,12 @@ public interface HasPropertyMetadata {* @throws UnsupportedOperationException if the entity does not support catalog properties.*/PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException;++ /**+ * Returns the schema property metadata.+ *+ * @return The schema property metadata.+ * @throws UnsupportedOperationException if the entity does not support schema properties.+ */+ PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException;}diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/PropertyEntry.java b/core/src/main/java/com/datastrato/gravitino/catalog/PropertyEntry.javaindex 89d5169f79..fe97207325 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/PropertyEntry.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/PropertyEntry.java@@ -237,6 +237,11 @@ public final class PropertyEntry<T> {return stringPropertyEntry(name, description, true, immutable, null, hidden, false);}+ public static PropertyEntry<String> stringOptionalPropertyEntry(+ String name, String description, boolean immutable, String defaultValue, boolean hidden) {+ return stringPropertyEntry(name, description, false, immutable, null, hidden, false);+ }+public static PropertyEntry<Integer> integerOptionalPropertyEntry(String name, String description, boolean immutable, int defaultValue, boolean hidden) {return integerPropertyEntry(name, description, false, immutable, defaultValue, hidden, false);diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedSchema.java b/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedSchema.javaindex 3a90ca647e..1e3cf7e94f 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedSchema.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedSchema.java@@ -9,6 +9,8 @@ import com.datastrato.gravitino.meta.AuditInfo;import com.datastrato.gravitino.meta.SchemaEntity;import com.datastrato.gravitino.rel.Schema;import java.util.Map;+import java.util.Set;+import java.util.stream.Collectors;/*** A Schema class to represent a schema metadata object that combines the metadata both from {@link@@ -19,6 +21,9 @@ public final class EntityCombinedSchema implements Schema {private final Schema schema;private final SchemaEntity schemaEntity;+ // Sets of properties that should be hidden from the user.+ private Set<String> hiddenProperties;+private EntityCombinedSchema(Schema schema, SchemaEntity schemaEntity) {this.schema = schema;this.schemaEntity = schemaEntity;@@ -32,6 +37,11 @@ public final class EntityCombinedSchema implements Schema {return of(schema, null);}+ public EntityCombinedSchema withHiddenPropertiesSet(Set<String> hiddenProperties) {+ this.hiddenProperties = hiddenProperties;+ return this;+ }+@Overridepublic String name() {return schema.name();@@ -44,7 +54,9 @@ public final class EntityCombinedSchema implements Schema {@Overridepublic Map<String, String> properties() {- return schema.properties();+ return schema.properties().entrySet().stream()+ .filter(e -> !hiddenProperties.contains(e.getKey()))+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));}@Overridediff --git a/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedTable.java b/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedTable.javaindex d05caec6df..ee50ad6c03 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedTable.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/rel/EntityCombinedTable.java@@ -38,6 +38,10 @@ public final class EntityCombinedTable implements Table {return new EntityCombinedTable(table, tableEntity);}+ public static EntityCombinedTable of(Table table) {+ return new EntityCombinedTable(table, null);+ }+public EntityCombinedTable withHiddenPropertiesSet(Set<String> hiddenProperties) {this.hiddenProperties = hiddenProperties;return this;diff --git a/core/src/test/java/com/datastrato/gravitino/TestCatalogOperations.java b/core/src/test/java/com/datastrato/gravitino/TestCatalogOperations.javaindex 9856fef610..72aed3d5b1 100644--- a/core/src/test/java/com/datastrato/gravitino/TestCatalogOperations.java+++ b/core/src/test/java/com/datastrato/gravitino/TestCatalogOperations.java@@ -39,12 +39,15 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, Sprivate final Map<NameIdentifier, TestSchema> schemas;private final BasePropertiesMetadata tablePropertiesMetadata;++ private final BasePropertiesMetadata schemaPropertiesMetadata;private Map<String, String> config;public TestCatalogOperations(Map<String, String> config) {tables = Maps.newHashMap();schemas = Maps.newHashMap();tablePropertiesMetadata = new TestBasePropertiesMetadata();+ schemaPropertiesMetadata = new TestBasePropertiesMetadata();this.config = config;}@@ -278,6 +281,11 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, Sreturn tablePropertiesMetadata;}+ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ return schemaPropertiesMetadata;+ }+@Overridepublic PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {if (config.containsKey("mock")) {diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogOperationDispatcher.javaindex 67936a30d1..7b0aa05832 100644--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogOperationDispatcher.java+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestCatalogOperationDispatcher.java@@ -54,6 +54,7 @@ import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.function.Executable;public class TestCatalogOperationDispatcher {@@ -127,15 +128,34 @@ public class TestCatalogOperationDispatcher {// Check if the created Schema's field values are correctAssertions.assertEquals("schema1", schema.name());Assertions.assertEquals("comment", schema.comment());- testProperties(props, schema.properties(), true);+ testProperties(props, schema.properties());++ // Test required table properties exception+ Map<String, String> illegalTableProperties =+ new HashMap<String, String>() {+ {+ put("k2", "v2");+ }+ };++ testPropertyException(+ () -> dispatcher.createSchema(schemaIdent, "comment", illegalTableProperties),+ "Properties are required and must be set");++ // Test reserved table properties exception+ illegalTableProperties.put(COMMENT_KEY, "table comment");+ illegalTableProperties.put(ID_KEY, "gravitino.v1.uidfdsafdsa");+ testPropertyException(+ () -> dispatcher.createSchema(schemaIdent, "comment", illegalTableProperties),+ "Properties are reserved and cannot be set",+ "comment",+ "gravitino.identifier");// Check if the Schema entity is stored in the EntityStoreSchemaEntity schemaEntity = entityStore.get(schemaIdent, SCHEMA, SchemaEntity.class);Assertions.assertNotNull(schemaEntity);Assertions.assertEquals("schema1", schemaEntity.name());-- StringIdentifier stringId = StringIdentifier.fromProperties(schema.properties());- Assertions.assertEquals(stringId.id(), schemaEntity.id());+ Assertions.assertNotNull(schemaEntity.id());Optional<NameIdentifier> ident1 =Arrays.stream(dispatcher.listSchemas(ns))@@ -151,7 +171,7 @@ public class TestCatalogOperationDispatcher {// Check if the created Schema's field values are correctAssertions.assertEquals("schema2", schema2.name());Assertions.assertEquals("comment", schema2.comment());- testProperties(props, schema2.properties(), true);+ testProperties(props, schema2.properties());// Check if the Schema entity is stored in the EntityStoreAssertions.assertFalse(entityStore.exists(schemaIdent2, SCHEMA));@@ -172,7 +192,7 @@ public class TestCatalogOperationDispatcher {Schema loadedSchema = dispatcher.loadSchema(schemaIdent);Assertions.assertEquals(schema.name(), loadedSchema.name());Assertions.assertEquals(schema.comment(), loadedSchema.comment());- testProperties(schema.properties(), loadedSchema.properties(), true);+ testProperties(schema.properties(), loadedSchema.properties());// Audit info is gotten from entity storeAssertions.assertEquals("gravitino", loadedSchema.auditInfo().creator());@@ -214,6 +234,13 @@ public class TestCatalogOperationDispatcher {Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");Schema schema = dispatcher.createSchema(schemaIdent, "comment", props);+ // Test immutable schema properties+ SchemaChange[] illegalChange =+ new SchemaChange[] {SchemaChange.setProperty(COMMENT_KEY, "new comment")};+ testPropertyException(+ () -> dispatcher.alterSchema(schemaIdent, illegalChange),+ "Property comment is immutable or reserved, cannot be set");+SchemaChange[] changes =new SchemaChange[] {SchemaChange.setProperty("k3", "v3"), SchemaChange.removeProperty("k1")@@ -223,7 +250,7 @@ public class TestCatalogOperationDispatcher {Assertions.assertEquals(schema.name(), alteredSchema.name());Assertions.assertEquals(schema.comment(), alteredSchema.comment());Map<String, String> expectedProps = ImmutableMap.of("k2", "v2", "k3", "v3");- testProperties(expectedProps, alteredSchema.properties(), true);+ testProperties(expectedProps, alteredSchema.properties());// Audit info is gotten from gravitino entity store.Assertions.assertEquals("gravitino", alteredSchema.auditInfo().creator());Assertions.assertEquals("gravitino", alteredSchema.auditInfo().lastModifier());@@ -235,7 +262,7 @@ public class TestCatalogOperationDispatcher {Schema alteredSchema1 = dispatcher.alterSchema(schemaIdent, changes);Assertions.assertEquals(schema.name(), alteredSchema1.name());Assertions.assertEquals(schema.comment(), alteredSchema1.comment());- testProperties(expectedProps, alteredSchema1.properties(), true);+ testProperties(expectedProps, alteredSchema1.properties());// Audit info is gotten from catalog, not from the entity storeAssertions.assertEquals("test", alteredSchema1.auditInfo().creator());Assertions.assertEquals("test", alteredSchema1.auditInfo().lastModifier());@@ -246,7 +273,7 @@ public class TestCatalogOperationDispatcher {Schema alteredSchema2 = dispatcher.alterSchema(schemaIdent, changes);Assertions.assertEquals(schema.name(), alteredSchema2.name());Assertions.assertEquals(schema.comment(), alteredSchema2.comment());- testProperties(expectedProps, alteredSchema2.properties(), true);+ testProperties(expectedProps, alteredSchema2.properties());// Audit info is gotten from catalog, not from the entity storeAssertions.assertEquals("test", alteredSchema2.auditInfo().creator());Assertions.assertEquals("test", alteredSchema1.auditInfo().lastModifier());@@ -268,7 +295,7 @@ public class TestCatalogOperationDispatcher {Schema alteredSchema3 = dispatcher.alterSchema(schemaIdent, changes);Assertions.assertEquals(schema.name(), alteredSchema3.name());Assertions.assertEquals(schema.comment(), alteredSchema3.comment());- testProperties(expectedProps, alteredSchema3.properties(), true);+ testProperties(expectedProps, alteredSchema3.properties());// Audit info is gotten from catalog, not from the entity storeAssertions.assertEquals("test", alteredSchema3.auditInfo().creator());Assertions.assertEquals("test", alteredSchema1.auditInfo().lastModifier());@@ -294,7 +321,7 @@ public class TestCatalogOperationDispatcher {public void testCreateAndListTables() throws IOException {Namespace tableNs = Namespace.of(metalake, catalog, "schema41");Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");- Schema schema = dispatcher.createSchema(NameIdentifier.of(tableNs.levels()), "comment", props);+ dispatcher.createSchema(NameIdentifier.of(tableNs.levels()), "comment", props);NameIdentifier tableIdent1 = NameIdentifier.of(tableNs, "table1");Column[] columns =@@ -306,7 +333,7 @@ public class TestCatalogOperationDispatcher {Table table1 = dispatcher.createTable(tableIdent1, columns, "comment", props, new Transform[0]);Assertions.assertEquals("table1", table1.name());Assertions.assertEquals("comment", table1.comment());- testProperties(props, table1.properties(), false);+ testProperties(props, table1.properties());Assertions.assertEquals(0, table1.partitioning().length);Assertions.assertArrayEquals(columns, table1.columns());@@ -317,31 +344,22 @@ public class TestCatalogOperationDispatcher {put("k2", "v2");}};-- IllegalArgumentException exception =- assertThrows(- IllegalArgumentException.class,- () ->- dispatcher.createTable(- tableIdent1, columns, "comment", illegalTableProperties, new Transform[0]));- Assertions.assertTrue(- exception.getMessage().contains("Properties are required and must be set"));+ testPropertyException(+ () ->+ dispatcher.createTable(+ tableIdent1, columns, "comment", illegalTableProperties, new Transform[0]),+ "Properties are required and must be set");// Test reserved table properties exceptionillegalTableProperties.put(COMMENT_KEY, "table comment");illegalTableProperties.put(ID_KEY, "gravitino.v1.uidfdsafdsa");- IllegalArgumentException exception1 =- assertThrows(- IllegalArgumentException.class,- () ->- dispatcher.createTable(- tableIdent1, columns, "comment", illegalTableProperties, new Transform[0]));-- // [comment, gravitino.identifier] is a set, we can guarantee the sequences of elements in it- Assertions.assertTrue(- exception1.getMessage().contains("Properties are reserved and cannot be set")- && exception1.getMessage().contains("comment")- && exception1.getMessage().contains("gravitino.identifier"));+ testPropertyException(+ () ->+ dispatcher.createTable(+ tableIdent1, columns, "comment", illegalTableProperties, new Transform[0]),+ "Properties are reserved and cannot be set",+ "comment",+ "gravitino.identifier");// Check if the Table entity is stored in the EntityStoreTableEntity tableEntity = entityStore.get(tableIdent1, TABLE, TableEntity.class);@@ -364,7 +382,7 @@ public class TestCatalogOperationDispatcher {// Check if the created Schema's field values are correctAssertions.assertEquals("table2", table2.name());Assertions.assertEquals("comment", table2.comment());- testProperties(props, table2.properties(), false);+ testProperties(props, table2.properties());// Check if the Table entity is stored in the EntityStoreAssertions.assertFalse(entityStore.exists(tableIdent2, TABLE));@@ -392,7 +410,7 @@ public class TestCatalogOperationDispatcher {Table loadedTable1 = dispatcher.loadTable(tableIdent1);Assertions.assertEquals(table1.name(), loadedTable1.name());Assertions.assertEquals(table1.comment(), loadedTable1.comment());- testProperties(table1.properties(), loadedTable1.properties(), false);+ testProperties(table1.properties(), loadedTable1.properties());Assertions.assertEquals(0, loadedTable1.partitioning().length);Assertions.assertArrayEquals(table1.columns(), loadedTable1.columns());// Audit info is gotten from the entity store@@ -447,14 +465,11 @@ public class TestCatalogOperationDispatcher {Table table = dispatcher.createTable(tableIdent, columns, "comment", props, new Transform[0]);// Test immutable table properties- TableChange[] illegalChange1 =+ TableChange[] illegalChange =new TableChange[] {TableChange.setProperty(COMMENT_KEY, "new comment")};- IllegalArgumentException exception =- assertThrows(- IllegalArgumentException.class,- () -> dispatcher.alterTable(tableIdent, illegalChange1));- Assertions.assertEquals(- "Property comment is immutable or reserved, cannot be set", exception.getMessage());+ testPropertyException(+ () -> dispatcher.alterTable(tableIdent, illegalChange),+ "Property comment is immutable or reserved, cannot be set");TableChange[] changes =new TableChange[] {TableChange.setProperty("k3", "v3"), TableChange.removeProperty("k1")};@@ -463,7 +478,7 @@ public class TestCatalogOperationDispatcher {Assertions.assertEquals(table.name(), alteredTable.name());Assertions.assertEquals(table.comment(), alteredTable.comment());Map<String, String> expectedProps = ImmutableMap.of("k2", "v2", "k3", "v3");- testProperties(expectedProps, alteredTable.properties(), false);+ testProperties(expectedProps, alteredTable.properties());// Audit info is gotten from gravitino entity storeAssertions.assertEquals("gravitino", alteredTable.auditInfo().creator());Assertions.assertEquals("gravitino", alteredTable.auditInfo().lastModifier());@@ -545,20 +560,18 @@ public class TestCatalogOperationDispatcher {assertEquals(dispatcher.getCatalogIdentifier(id5), NameIdentifier.of("a", "b"));}- private void testProperties(- Map<String, String> expectedProps, Map<String, String> testProps, boolean validateIDKey) {+ private void testProperties(Map<String, String> expectedProps, Map<String, String> testProps) {expectedProps.forEach((k, v) -> {Assertions.assertEquals(v, testProps.get(k));});+ Assertions.assertFalse(testProps.containsKey(StringIdentifier.ID_KEY));+ }- if (validateIDKey) {- Assertions.assertTrue(testProps.containsKey(StringIdentifier.ID_KEY));- StringIdentifier StringId =- StringIdentifier.fromString(testProps.get(StringIdentifier.ID_KEY));- Assertions.assertEquals(StringId.toString(), testProps.get(StringIdentifier.ID_KEY));- } else {- Assertions.assertFalse(testProps.containsKey(StringIdentifier.ID_KEY));+ private void testPropertyException(Executable operation, String... errorMessage) {+ IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, operation);+ for (String msg : errorMessage) {+ Assertions.assertTrue(exception.getMessage().contains(msg));}}}diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalog.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalog.javaindex 4f79341fea..3bff1283ac 100644--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalog.java+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestCatalog.java@@ -25,6 +25,11 @@ public class TestCatalog extends BaseCatalog<TestCatalog> {throw new UnsupportedOperationException();}+ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ throw new UnsupportedOperationException();+ }+@Overridepublic void initialize(Map<String, String> config) throws RuntimeException {}