World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1526] feat(catalog-fileset): Add Schema support for Hadoop fileset catalog (#1602)
Jerry Shao420a3f5f6c35
diff --git a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogOperations.java b/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogOperations.javadeleted file mode 100644index 45e9162d0c..0000000000--- a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogOperations.java+++ /dev/null@@ -1,153 +0,0 @@-/*- * Copyright 2024 Datastrato Pvt Ltd.- * This software is licensed under the Apache License version 2.- */-package com.datastrato.gravitino.catalog.file;--import com.datastrato.gravitino.Entity;-import com.datastrato.gravitino.EntityStore;-import com.datastrato.gravitino.GravitinoEnv;-import com.datastrato.gravitino.NameIdentifier;-import com.datastrato.gravitino.Namespace;-import com.datastrato.gravitino.catalog.CatalogOperations;-import com.datastrato.gravitino.catalog.PropertiesMetadata;-import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;-import com.datastrato.gravitino.exceptions.NoSuchCatalogException;-import com.datastrato.gravitino.exceptions.NoSuchFilesetException;-import com.datastrato.gravitino.exceptions.NoSuchSchemaException;-import com.datastrato.gravitino.exceptions.NonEmptySchemaException;-import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;-import com.datastrato.gravitino.file.Fileset;-import com.datastrato.gravitino.file.FilesetCatalog;-import com.datastrato.gravitino.file.FilesetChange;-import com.datastrato.gravitino.meta.CatalogEntity;-import com.datastrato.gravitino.meta.SchemaEntity;-import com.datastrato.gravitino.rel.Schema;-import com.datastrato.gravitino.rel.SchemaChange;-import com.datastrato.gravitino.rel.SupportsSchemas;-import com.datastrato.gravitino.storage.IdGenerator;-import java.io.IOException;-import java.util.List;-import java.util.Map;--public class HadoopCatalogOperations implements CatalogOperations, SupportsSchemas, FilesetCatalog {-- private static final HadoopCatalogPropertiesMetadata CATALOG_PROPERTIES_METADATA =- new HadoopCatalogPropertiesMetadata();-- private static final HadoopSchemaPropertiesMetadata SCHEMA_PROPERTIES_METADATA =- new HadoopSchemaPropertiesMetadata();-- private static final HadoopFilesetPropertiesMetadata FILESET_PROPERTIES_METADATA =- new HadoopFilesetPropertiesMetadata();-- private final CatalogEntity entity;-- private final EntityStore store;-- private final IdGenerator idGenerator;-- public HadoopCatalogOperations(CatalogEntity entity, GravitinoEnv env) {- this.entity = entity;- this.store = env.entityStore();- this.idGenerator = env.idGenerator();- }-- public HadoopCatalogOperations(CatalogEntity entity) {- this(entity, GravitinoEnv.getInstance());- }-- @Override- public void initialize(Map<String, String> config) throws RuntimeException {}-- @Override- public NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException {- throw new UnsupportedOperationException();- }-- @Override- public Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {- throw new UnsupportedOperationException();- }-- @Override- public Fileset createFileset(- NameIdentifier ident,- String comment,- Fileset.Type type,- String storageLocation,- Map<String, String> properties)- throws NoSuchSchemaException, FilesetAlreadyExistsException {- throw new UnsupportedOperationException();- }-- @Override- public Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)- throws NoSuchFilesetException, IllegalArgumentException {- throw new UnsupportedOperationException();- }-- @Override- public boolean dropFileset(NameIdentifier ident) {- throw new UnsupportedOperationException();- }-- @Override- public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {- try {- List<SchemaEntity> schemas =- store.list(namespace, SchemaEntity.class, Entity.EntityType.SCHEMA);- return schemas.stream()- .map(s -> NameIdentifier.of(namespace, s.name()))- .toArray(NameIdentifier[]::new);- } catch (IOException e) {- throw new RuntimeException("Failed to list schemas under namespace " + namespace, e);- }- }-- @Override- public Schema createSchema(NameIdentifier ident, String comment, Map<String, String> properties)- throws NoSuchCatalogException, SchemaAlreadyExistsException {- throw new UnsupportedOperationException();- }-- @Override- public Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {- throw new UnsupportedOperationException();- }-- @Override- public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)- throws NoSuchSchemaException {- throw new UnsupportedOperationException();- }-- @Override- public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {- throw new UnsupportedOperationException();- }-- @Override- public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {- throw new UnsupportedOperationException(- "Hadoop fileset catalog doesn't support table related operations");- }-- @Override- public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {- return CATALOG_PROPERTIES_METADATA;- }-- @Override- public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {- return SCHEMA_PROPERTIES_METADATA;- }-- @Override- public PropertiesMetadata filesetPropertiesMetadata() throws UnsupportedOperationException {- return FILESET_PROPERTIES_METADATA;- }-- @Override- public void close() throws IOException {}-}diff --git a/catalogs/catalog-fileset/build.gradle.kts b/catalogs/catalog-hadoop/build.gradle.ktssimilarity index 81%rename from catalogs/catalog-fileset/build.gradle.ktsrename to catalogs/catalog-hadoop/build.gradle.ktsindex 232f3a5da2..9ddde02d14 100644--- a/catalogs/catalog-fileset/build.gradle.kts+++ b/catalogs/catalog-hadoop/build.gradle.kts@@ -2,7 +2,7 @@* Copyright 2024 Datastrato Pvt Ltd.* This software is licensed under the Apache License version 2.*/-description = "catalog-fileset"+description = "catalog-hadoop"plugins {`maven-publish`@@ -13,9 +13,12 @@ plugins {dependencies {implementation(project(":api"))implementation(project(":core"))+ implementation(project(":common"))implementation(libs.slf4j.api)implementation(libs.guava)+ implementation(libs.hadoop2.common)+ implementation(libs.hadoop2.hdfs)testImplementation(libs.junit.jupiter.api)testRuntimeOnly(libs.junit.jupiter.engine)@@ -31,12 +34,12 @@ tasks {val copyCatalogLibs by registering(Copy::class) {dependsOn(copyDepends, "build")from("build/libs_all", "build/libs")- into("$rootDir/distribution/package/catalogs/fileset/libs")+ into("$rootDir/distribution/package/catalogs/hadoop/libs")}val copyCatalogConfig by registering(Copy::class) {from("src/main/resources")- into("$rootDir/distribution/package/catalogs/fileset/conf")+ into("$rootDir/distribution/package/catalogs/hadoop/conf")// TODO. add configuration file later on.diff --git a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalog.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalog.javasimilarity index 95%rename from catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalog.javarename to catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalog.javaindex e1cee52e9c..6aef14bb74 100644--- a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalog.java+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalog.java@@ -2,7 +2,7 @@* Copyright 2024 Datastrato Pvt Ltd.* This software is licensed under the Apache License version 2.*/-package com.datastrato.gravitino.catalog.file;+package com.datastrato.gravitino.catalog.hadoop;import com.datastrato.gravitino.catalog.BaseCatalog;import com.datastrato.gravitino.catalog.CatalogOperations;diff --git a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.javanew file mode 100644index 0000000000..011ec879c1--- /dev/null+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogOperations.java@@ -0,0 +1,387 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.catalog.hadoop;++import static com.datastrato.gravitino.catalog.BaseCatalog.CATALOG_BYPASS_PREFIX;++import com.datastrato.gravitino.Entity;+import com.datastrato.gravitino.EntityStore;+import com.datastrato.gravitino.GravitinoEnv;+import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.StringIdentifier;+import com.datastrato.gravitino.catalog.CatalogOperations;+import com.datastrato.gravitino.catalog.PropertiesMetadata;+import com.datastrato.gravitino.exceptions.AlreadyExistsException;+import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;+import com.datastrato.gravitino.exceptions.NoSuchCatalogException;+import com.datastrato.gravitino.exceptions.NoSuchEntityException;+import com.datastrato.gravitino.exceptions.NoSuchFilesetException;+import com.datastrato.gravitino.exceptions.NoSuchSchemaException;+import com.datastrato.gravitino.exceptions.NonEmptySchemaException;+import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;+import com.datastrato.gravitino.file.Fileset;+import com.datastrato.gravitino.file.FilesetCatalog;+import com.datastrato.gravitino.file.FilesetChange;+import com.datastrato.gravitino.meta.AuditInfo;+import com.datastrato.gravitino.meta.CatalogEntity;+import com.datastrato.gravitino.meta.SchemaEntity;+import com.datastrato.gravitino.rel.Schema;+import com.datastrato.gravitino.rel.SchemaChange;+import com.datastrato.gravitino.rel.SupportsSchemas;+import com.datastrato.gravitino.storage.IdGenerator;+import com.datastrato.gravitino.utils.PrincipalUtils;+import com.google.common.annotations.VisibleForTesting;+import com.google.common.base.Preconditions;+import com.google.common.collect.ImmutableMap;+import com.google.common.collect.Maps;+import java.io.IOException;+import java.time.Instant;+import java.util.Collections;+import java.util.List;+import java.util.Map;+import java.util.Optional;+import java.util.stream.Collectors;+import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++public class HadoopCatalogOperations implements CatalogOperations, SupportsSchemas, FilesetCatalog {++ private static final Logger LOG = LoggerFactory.getLogger(HadoopCatalogOperations.class);++ private static final HadoopCatalogPropertiesMetadata CATALOG_PROPERTIES_METADATA =+ new HadoopCatalogPropertiesMetadata();++ private static final HadoopSchemaPropertiesMetadata SCHEMA_PROPERTIES_METADATA =+ new HadoopSchemaPropertiesMetadata();++ private static final HadoopFilesetPropertiesMetadata FILESET_PROPERTIES_METADATA =+ new HadoopFilesetPropertiesMetadata();++ private final CatalogEntity entity;++ private final EntityStore store;++ private final IdGenerator idGenerator;++ @VisibleForTesting Configuration hadoopConf;++ @VisibleForTesting Optional<Path> catalogStorageLocation;++ // For testing only.+ HadoopCatalogOperations(CatalogEntity entity, EntityStore store, IdGenerator idGenerator) {+ this.entity = entity;+ this.store = store;+ this.idGenerator = idGenerator;+ }++ public HadoopCatalogOperations(CatalogEntity entity) {+ this(+ entity, GravitinoEnv.getInstance().entityStore(), GravitinoEnv.getInstance().idGenerator());+ }++ @Override+ public void initialize(Map<String, String> config) throws RuntimeException {+ // Initialize Hadoop Configuration.+ this.hadoopConf = new Configuration();+ Map<String, String> bypassConfigs =+ config.entrySet().stream()+ .filter(e -> e.getKey().startsWith(CATALOG_BYPASS_PREFIX))+ .collect(+ Collectors.toMap(+ e -> e.getKey().substring(CATALOG_BYPASS_PREFIX.length()),+ Map.Entry::getValue));+ bypassConfigs.forEach(hadoopConf::set);++ String catalogLocation =+ (String)+ CATALOG_PROPERTIES_METADATA.getOrDefault(+ config, HadoopCatalogPropertiesMetadata.LOCATION);+ this.catalogStorageLocation = Optional.ofNullable(catalogLocation).map(Path::new);+ }++ @Override+ public NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException {+ throw new UnsupportedOperationException();+ }++ @Override+ public Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException {+ throw new UnsupportedOperationException();+ }++ @Override+ public Fileset createFileset(+ NameIdentifier ident,+ String comment,+ Fileset.Type type,+ String storageLocation,+ Map<String, String> properties)+ throws NoSuchSchemaException, FilesetAlreadyExistsException {+ throw new UnsupportedOperationException();+ }++ @Override+ public Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)+ throws NoSuchFilesetException, IllegalArgumentException {+ throw new UnsupportedOperationException();+ }++ @Override+ public boolean dropFileset(NameIdentifier ident) {+ throw new UnsupportedOperationException();+ }++ @Override+ public NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {+ try {+ List<SchemaEntity> schemas =+ store.list(namespace, SchemaEntity.class, Entity.EntityType.SCHEMA);+ return schemas.stream()+ .map(s -> NameIdentifier.of(namespace, s.name()))+ .toArray(NameIdentifier[]::new);+ } catch (IOException e) {+ throw new RuntimeException("Failed to list schemas under namespace " + namespace, e);+ }+ }++ @Override+ public Schema createSchema(NameIdentifier ident, String comment, Map<String, String> properties)+ throws NoSuchCatalogException, SchemaAlreadyExistsException {+ try {+ if (store.exists(ident, Entity.EntityType.SCHEMA)) {+ throw new SchemaAlreadyExistsException("Schema " + ident.name() + " already exists");+ }+ } catch (IOException ioe) {+ throw new RuntimeException("Failed to check if schema " + ident.name() + " exists", ioe);+ }++ String schemaLocation =+ (String)+ SCHEMA_PROPERTIES_METADATA.getOrDefault(+ properties, HadoopSchemaPropertiesMetadata.LOCATION);+ Path schemaPath =+ Optional.ofNullable(schemaLocation)+ .map(Path::new)+ .orElse(catalogStorageLocation.map(p -> new Path(p, ident.name())).orElse(null));++ if (schemaPath != null) {+ try {+ FileSystem fs = schemaPath.getFileSystem(hadoopConf);+ if (fs.exists(schemaPath)) {+ throw new SchemaAlreadyExistsException(+ "Schema " + ident.name() + " location " + schemaPath + " already exists");+ }++ if (!fs.mkdirs(schemaPath)) {+ // Fail the operation when failed to create the schema path.+ throw new RuntimeException(+ "Failed to create schema " + ident.name() + " location " + schemaPath);+ }+ } catch (IOException ioe) {+ throw new RuntimeException(+ "Failed to create schema " + ident.name() + " location " + schemaPath, ioe);+ }++ LOG.info("Created schema {} location {}", ident.name(), schemaPath);+ }++ StringIdentifier stringId = StringIdentifier.fromProperties(properties);+ Preconditions.checkNotNull(stringId, "Property String identifier should not be null");++ SchemaEntity schemaEntity =+ new SchemaEntity.Builder()+ .withName(ident.name())+ .withId(stringId.id())+ .withNamespace(ident.namespace())+ .withComment(comment)+ .withProperties(addManagedFlagToProperties(properties))+ .withAuditInfo(+ new AuditInfo.Builder()+ .withCreator(PrincipalUtils.getCurrentPrincipal().getName())+ .withCreateTime(Instant.now())+ .build())+ .build();+ try {+ store.put(schemaEntity, true /* overwrite */);+ } catch (IOException ioe) {+ throw new RuntimeException("Failed to create schema " + ident.name(), ioe);+ }++ return new HadoopSchema.Builder()+ .withName(ident.name())+ .withComment(comment)+ .withProperties(schemaEntity.properties())+ .withAuditInfo(schemaEntity.auditInfo())+ .build();+ }++ @Override+ public Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {+ try {+ SchemaEntity schemaEntity = store.get(ident, Entity.EntityType.SCHEMA, SchemaEntity.class);++ return new HadoopSchema.Builder()+ .withName(ident.name())+ .withComment(schemaEntity.comment())+ .withProperties(schemaEntity.properties())+ .withAuditInfo(schemaEntity.auditInfo())+ .build();++ } catch (NoSuchEntityException exception) {+ throw new NoSuchSchemaException("Schema " + ident.name() + " does not exist", exception);+ } catch (IOException ioe) {+ throw new RuntimeException("Failed to load schema " + ident.name(), ioe);+ }+ }++ @Override+ public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)+ throws NoSuchSchemaException {+ try {+ if (!store.exists(ident, Entity.EntityType.SCHEMA)) {+ throw new NoSuchSchemaException("Schema " + ident.name() + " does not exist");+ }+ } catch (IOException ioe) {+ throw new RuntimeException("Failed to check if schema " + ident.name() + " exists", ioe);+ }++ try {+ SchemaEntity entity =+ store.update(+ ident,+ SchemaEntity.class,+ Entity.EntityType.SCHEMA,+ schemaEntity -> updateSchemaEntity(ident, schemaEntity, changes));++ return new HadoopSchema.Builder()+ .withName(ident.name())+ .withComment(entity.comment())+ .withProperties(entity.properties())+ .withAuditInfo(entity.auditInfo())+ .build();++ } catch (IOException ioe) {+ throw new RuntimeException("Failed to update schema " + ident.name(), ioe);+ } catch (NoSuchEntityException nsee) {+ throw new NoSuchSchemaException("Schema " + ident.name() + " does not exist", nsee);+ } catch (AlreadyExistsException aee) {+ throw new RuntimeException(+ "Schema "+ + ident.name()+ + " already exists, this is unexpected because schema doesn't support rename",+ aee);+ }+ }++ @Override+ public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {+ try {+ SchemaEntity schemaEntity = store.get(ident, Entity.EntityType.SCHEMA, SchemaEntity.class);+ Map<String, String> properties =+ Optional.ofNullable(schemaEntity.properties()).orElse(Collections.emptyMap());++ String schemaLocation =+ (String)+ SCHEMA_PROPERTIES_METADATA.getOrDefault(+ properties, HadoopSchemaPropertiesMetadata.LOCATION);+ Path schemaPath =+ Optional.ofNullable(schemaLocation)+ .map(Path::new)+ .orElse(catalogStorageLocation.map(p -> new Path(p, ident.name())).orElse(null));++ // Nothing to delete if the schema path is not set.+ if (schemaPath == null) {+ return true;+ }++ FileSystem fs = schemaPath.getFileSystem(hadoopConf);+ // Nothing to delete if the schema path does not exist.+ if (!fs.exists(schemaPath)) {+ return true;+ }++ if (fs.listStatus(schemaPath).length > 0 && !cascade) {+ throw new NonEmptySchemaException(+ "Schema " + ident.name() + " with location " + schemaPath + " is not empty");+ } else {+ fs.delete(schemaPath, true);+ }++ LOG.info("Deleted schema {} location {}", ident.name(), schemaPath);+ return true;++ } catch (IOException ioe) {+ throw new RuntimeException("Failed to delete schema " + ident.name() + " location", ioe);+ }+ }++ @Override+ public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {+ throw new UnsupportedOperationException(+ "Hadoop fileset catalog doesn't support table related operations");+ }++ @Override+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {+ return CATALOG_PROPERTIES_METADATA;+ }++ @Override+ public PropertiesMetadata schemaPropertiesMetadata() throws UnsupportedOperationException {+ return SCHEMA_PROPERTIES_METADATA;+ }++ @Override+ public PropertiesMetadata filesetPropertiesMetadata() throws UnsupportedOperationException {+ return FILESET_PROPERTIES_METADATA;+ }++ @Override+ public void close() throws IOException {}++ private Map<String, String> addManagedFlagToProperties(Map<String, String> properties) {+ return ImmutableMap.<String, String>builder()+ .putAll(properties)+ .put(HadoopSchemaPropertiesMetadata.GRAVITINO_MANAGED_ENTITY, Boolean.TRUE.toString())+ .build();+ }++ private SchemaEntity updateSchemaEntity(+ NameIdentifier ident, SchemaEntity schemaEntity, SchemaChange... changes) {+ Map<String, String> props = Maps.newHashMap(schemaEntity.properties());++ for (SchemaChange change : changes) {+ if (change instanceof SchemaChange.SetProperty) {+ SchemaChange.SetProperty setProperty = (SchemaChange.SetProperty) change;+ props.put(setProperty.getProperty(), setProperty.getValue());+ } else if (change instanceof SchemaChange.RemoveProperty) {+ SchemaChange.RemoveProperty removeProperty = (SchemaChange.RemoveProperty) change;+ props.remove(removeProperty.getProperty());+ } else {+ throw new IllegalArgumentException(+ "Unsupported schema change: " + change.getClass().getSimpleName());+ }+ }++ return new SchemaEntity.Builder()+ .withName(schemaEntity.name())+ .withNamespace(ident.namespace())+ .withId(schemaEntity.id())+ .withComment(schemaEntity.comment())+ .withProperties(props)+ .withAuditInfo(+ new AuditInfo.Builder()+ .withCreator(schemaEntity.auditInfo().creator())+ .withCreateTime(schemaEntity.auditInfo().createTime())+ .withLastModifier(PrincipalUtils.getCurrentPrincipal().getName())+ .withCreateTime(Instant.now())+ .build())+ .build();+ }+}diff --git a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogPropertiesMetadata.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogPropertiesMetadata.javasimilarity index 96%rename from catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogPropertiesMetadata.javarename to catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogPropertiesMetadata.javaindex d166f65bcd..2545ca95a0 100644--- a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopCatalogPropertiesMetadata.java+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopCatalogPropertiesMetadata.java@@ -2,7 +2,7 @@* Copyright 2024 Datastrato Pvt Ltd.* This software is licensed under the Apache License version 2.*/-package com.datastrato.gravitino.catalog.file;+package com.datastrato.gravitino.catalog.hadoop;import com.datastrato.gravitino.catalog.BaseCatalogPropertiesMetadata;import com.datastrato.gravitino.catalog.PropertyEntry;diff --git a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopFilesetPropertiesMetadata.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopFilesetPropertiesMetadata.javasimilarity index 90%rename from catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopFilesetPropertiesMetadata.javarename to catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopFilesetPropertiesMetadata.javaindex 30323c423d..6d3bef4c68 100644--- a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopFilesetPropertiesMetadata.java+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopFilesetPropertiesMetadata.java@@ -2,7 +2,7 @@* Copyright 2024 Datastrato Pvt Ltd.* This software is licensed under the Apache License version 2.*/-package com.datastrato.gravitino.catalog.file;+package com.datastrato.gravitino.catalog.hadoop;import com.datastrato.gravitino.catalog.BasePropertiesMetadata;import com.datastrato.gravitino.catalog.PropertyEntry;diff --git a/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchema.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchema.javanew file mode 100644index 0000000000..f3caea68ea--- /dev/null+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchema.java@@ -0,0 +1,23 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.catalog.hadoop;++import com.datastrato.gravitino.catalog.rel.BaseSchema;++public class HadoopSchema extends BaseSchema {++ public static class Builder extends BaseSchemaBuilder<Builder, HadoopSchema> {++ @Override+ protected HadoopSchema internalBuild() {+ HadoopSchema schema = new HadoopSchema();+ schema.name = name;+ schema.comment = comment;+ schema.properties = properties;+ schema.auditInfo = auditInfo;+ return schema;+ }+ }+}diff --git a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopSchemaPropertiesMetadata.java b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchemaPropertiesMetadata.javasimilarity index 96%rename from catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopSchemaPropertiesMetadata.javarename to catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchemaPropertiesMetadata.javaindex ecb9e8dc5f..6c692b32ef 100644--- a/catalogs/catalog-fileset/src/main/java/com/datastrato/gravitino/catalog/file/HadoopSchemaPropertiesMetadata.java+++ b/catalogs/catalog-hadoop/src/main/java/com/datastrato/gravitino/catalog/hadoop/HadoopSchemaPropertiesMetadata.java@@ -2,7 +2,7 @@* Copyright 2024 Datastrato Pvt Ltd.* This software is licensed under the Apache License version 2.*/-package com.datastrato.gravitino.catalog.file;+package com.datastrato.gravitino.catalog.hadoop;import com.datastrato.gravitino.catalog.BasePropertiesMetadata;import com.datastrato.gravitino.catalog.PropertyEntry;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.javanew file mode 100644index 0000000000..8017062e28--- /dev/null+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java@@ -0,0 +1,354 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.catalog.hadoop;++import static com.datastrato.gravitino.Configs.DEFAULT_ENTITY_KV_STORE;+import static com.datastrato.gravitino.Configs.ENTITY_KV_STORE;+import static com.datastrato.gravitino.Configs.ENTITY_STORE;+import static com.datastrato.gravitino.Configs.ENTRY_KV_ROCKSDB_BACKEND_PATH;+import static com.datastrato.gravitino.Configs.KV_DELETE_AFTER_TIME;+import static com.datastrato.gravitino.Configs.STORE_TRANSACTION_MAX_SKEW_TIME;+import static com.datastrato.gravitino.catalog.BaseCatalog.CATALOG_BYPASS_PREFIX;++import com.datastrato.gravitino.Config;+import com.datastrato.gravitino.Configs;+import com.datastrato.gravitino.EntitySerDeFactory;+import com.datastrato.gravitino.EntityStore;+import com.datastrato.gravitino.EntityStoreFactory;+import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.StringIdentifier;+import com.datastrato.gravitino.catalog.BaseCatalogPropertiesMetadata;+import com.datastrato.gravitino.exceptions.NoSuchSchemaException;+import com.datastrato.gravitino.exceptions.NonEmptySchemaException;+import com.datastrato.gravitino.exceptions.SchemaAlreadyExistsException;+import com.datastrato.gravitino.rel.Schema;+import com.datastrato.gravitino.rel.SchemaChange;+import com.datastrato.gravitino.storage.IdGenerator;+import com.datastrato.gravitino.storage.RandomIdGenerator;+import com.google.common.collect.ImmutableMap;+import com.google.common.collect.Maps;+import java.io.IOException;+import java.util.Arrays;+import java.util.Map;+import java.util.Set;+import java.util.UUID;+import java.util.stream.Collectors;+import org.apache.commons.io.FileUtils;+import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;+import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.Test;+import org.mockito.Mockito;++public class TestHadoopCatalogOperations {++ private static final String ROCKS_DB_STORE_PATH =+ "/tmp/gravitino_test_entityStore_" + UUID.randomUUID().toString().replace("-", "");++ private static final String TEST_ROOT_PATH =+ "file:///tmp/gravitino_test_catalog_" + UUID.randomUUID().toString().replace("-", "");++ private static EntityStore store;++ private static IdGenerator idGenerator;++ @BeforeAll+ public static void setUp() {+ Config config = Mockito.mock(Config.class);+ Mockito.when(config.get(ENTITY_STORE)).thenReturn("kv");+ Mockito.when(config.get(ENTITY_KV_STORE)).thenReturn(DEFAULT_ENTITY_KV_STORE);+ Mockito.when(config.get(Configs.ENTITY_SERDE)).thenReturn("proto");+ Mockito.when(config.get(ENTRY_KV_ROCKSDB_BACKEND_PATH)).thenReturn(ROCKS_DB_STORE_PATH);++ Assertions.assertEquals(ROCKS_DB_STORE_PATH, config.get(ENTRY_KV_ROCKSDB_BACKEND_PATH));+ Mockito.when(config.get(STORE_TRANSACTION_MAX_SKEW_TIME)).thenReturn(1000L);+ Mockito.when(config.get(KV_DELETE_AFTER_TIME)).thenReturn(20 * 60 * 1000L);++ store = EntityStoreFactory.createEntityStore(config);+ store.initialize(config);+ store.setSerDe(EntitySerDeFactory.createEntitySerDe(config));+ idGenerator = new RandomIdGenerator();+ }++ @AfterAll+ public static void tearDown() throws IOException {+ store.close();+ FileUtils.deleteDirectory(FileUtils.getFile(ROCKS_DB_STORE_PATH));+ new Path(TEST_ROOT_PATH)+ .getFileSystem(new Configuration())+ .delete(new Path(TEST_ROOT_PATH), true);+ }++ @Test+ public void testHadoopCatalogConfiguration() {+ Map<String, String> emptyProps = Maps.newHashMap();+ HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator);+ ops.initialize(emptyProps);+ Configuration conf = ops.hadoopConf;+ String value = conf.get("fs.defaultFS");+ Assertions.assertEquals("file:///", value);++ emptyProps.put(CATALOG_BYPASS_PREFIX + "fs.defaultFS", "hdfs://localhost:9000");+ ops.initialize(emptyProps);+ Configuration conf1 = ops.hadoopConf;+ String value1 = conf1.get("fs.defaultFS");+ Assertions.assertEquals("hdfs://localhost:9000", value1);++ Assertions.assertFalse(ops.catalogStorageLocation.isPresent());++ emptyProps.put(HadoopCatalogPropertiesMetadata.LOCATION, "file:///tmp/catalog");+ ops.initialize(emptyProps);+ Assertions.assertTrue(ops.catalogStorageLocation.isPresent());+ Path expectedPath = new Path("file:///tmp/catalog");+ Assertions.assertEquals(expectedPath, ops.catalogStorageLocation.get());+ }++ @Test+ public void testCreateSchemaWithNoLocation() throws IOException {+ String name = "schema11";+ String comment = "comment11";+ Schema schema = createSchema(name, comment, null, null);+ Assertions.assertEquals(name, schema.name());+ Assertions.assertEquals(comment, schema.comment());+ Map<String, String> props = schema.properties();+ Assertions.assertTrue(+ props.containsKey(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertEquals(+ "true", props.get(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));++ Throwable exception =+ Assertions.assertThrows(+ SchemaAlreadyExistsException.class, () -> createSchema(name, comment, null, null));+ Assertions.assertEquals("Schema schema11 already exists", exception.getMessage());+ }++ @Test+ public void testCreateSchemaWithCatalogLocation() throws IOException {+ String name = "schema12";+ String comment = "comment12";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog12";+ Schema schema = createSchema(name, comment, catalogPath, null);+ Assertions.assertEquals(name, schema.name());++ Path schemaPath = new Path(catalogPath, name);+ FileSystem fs = schemaPath.getFileSystem(new Configuration());+ Assertions.assertTrue(fs.exists(schemaPath));+ Assertions.assertTrue(fs.isDirectory(schemaPath));+ Assertions.assertTrue(fs.listStatus(schemaPath).length == 0);+ }++ @Test+ public void testCreateSchemaWithSchemaLocation() throws IOException {+ String name = "schema13";+ String comment = "comment13";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog13";+ String schemaPath = catalogPath + "/" + name;+ Schema schema = createSchema(name, comment, null, schemaPath);+ Assertions.assertEquals(name, schema.name());++ Path schemaPath1 = new Path(schemaPath);+ FileSystem fs = schemaPath1.getFileSystem(new Configuration());+ Assertions.assertTrue(fs.exists(schemaPath1));+ Assertions.assertTrue(fs.isDirectory(schemaPath1));+ Assertions.assertTrue(fs.listStatus(schemaPath1).length == 0);++ // Test create schema on the same location+ String name1 = "schema13_1";+ Throwable exception =+ Assertions.assertThrows(+ SchemaAlreadyExistsException.class,+ () -> createSchema(name1, comment, null, schemaPath));+ Assertions.assertEquals(+ "Schema schema13_1 location " + schemaPath1 + " already exists", exception.getMessage());+ }++ @Test+ public void testCreateSchemaWithCatalogAndSchemaLocation() throws IOException {+ String name = "schema14";+ String comment = "comment14";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog14";+ String schemaPath = TEST_ROOT_PATH + "/" + "schema14";+ Schema schema = createSchema(name, comment, catalogPath, schemaPath);+ Assertions.assertEquals(name, schema.name());++ Path schemaPath1 = new Path(schemaPath);+ FileSystem fs = schemaPath1.getFileSystem(new Configuration());+ Assertions.assertTrue(fs.exists(schemaPath1));+ Assertions.assertTrue(fs.isDirectory(schemaPath1));+ Assertions.assertTrue(fs.listStatus(schemaPath1).length == 0);++ Assertions.assertFalse(fs.exists(new Path(catalogPath)));+ Assertions.assertFalse(fs.exists(new Path(catalogPath, name)));+ }++ @Test+ public void testLoadSchema() throws IOException {+ String name = "schema15";+ String comment = "comment15";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog15";+ Schema schema = createSchema(name, comment, catalogPath, null);+ Assertions.assertEquals(name, schema.name());++ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator)) {+ ops.initialize(Maps.newHashMap());+ Schema schema1 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Assertions.assertEquals(name, schema1.name());+ Assertions.assertEquals(comment, schema1.comment());++ Map<String, String> props = schema1.properties();+ Assertions.assertTrue(+ props.containsKey(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertEquals(+ "true", props.get(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertTrue(props.containsKey(StringIdentifier.ID_KEY));++ Throwable exception =+ Assertions.assertThrows(+ NoSuchSchemaException.class,+ () -> ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", "schema16")));+ Assertions.assertEquals("Schema schema16 does not exist", exception.getMessage());+ }+ }++ @Test+ public void testListSchema() throws IOException {+ String name = "schema17";+ String comment = "comment17";+ String name1 = "schema18";+ String comment1 = "comment18";+ createSchema(name, comment, null, null);+ createSchema(name1, comment1, null, null);++ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator)) {+ ops.initialize(Maps.newHashMap());+ 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)));+ }+ }++ @Test+ public void testAlterSchema() throws IOException {+ String name = "schema19";+ String comment = "comment19";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog19";+ Schema schema = createSchema(name, comment, catalogPath, null);+ Assertions.assertEquals(name, schema.name());++ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator)) {+ ops.initialize(Maps.newHashMap());+ Schema schema1 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Assertions.assertEquals(name, schema1.name());+ Assertions.assertEquals(comment, schema1.comment());++ Map<String, String> props = schema1.properties();+ Assertions.assertTrue(+ props.containsKey(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertEquals(+ "true", props.get(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertTrue(props.containsKey(StringIdentifier.ID_KEY));++ String newKey = "k1";+ String newValue = "v1";+ SchemaChange setProperty = SchemaChange.setProperty(newKey, newValue);+ Schema schema2 = ops.alterSchema(NameIdentifier.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));+ 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);+ 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));+ Map<String, String> props5 = schema5.properties();+ Assertions.assertFalse(props5.containsKey(newKey));+ }+ }++ @Test+ public void testDropSchema() throws IOException {+ String name = "schema20";+ String comment = "comment20";+ String catalogPath = TEST_ROOT_PATH + "/" + "catalog20";+ Schema schema = createSchema(name, comment, catalogPath, null);+ Assertions.assertEquals(name, schema.name());++ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator)) {+ ops.initialize(ImmutableMap.of(HadoopCatalogPropertiesMetadata.LOCATION, catalogPath));+ Schema schema1 = ops.loadSchema(NameIdentifier.ofSchema("m1", "c1", name));+ Assertions.assertEquals(name, schema1.name());+ Assertions.assertEquals(comment, schema1.comment());++ Map<String, String> props = schema1.properties();+ Assertions.assertTrue(+ props.containsKey(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertEquals(+ "true", props.get(BaseCatalogPropertiesMetadata.GRAVITINO_MANAGED_ENTITY));+ Assertions.assertTrue(props.containsKey(StringIdentifier.ID_KEY));++ ops.dropSchema(NameIdentifier.ofSchema("m1", "c1", name), false);++ Path schemaPath = new Path(new Path(catalogPath), name);+ FileSystem fs = schemaPath.getFileSystem(new Configuration());+ Assertions.assertFalse(fs.exists(schemaPath));++ // Test drop non-empty schema with cascade = false+ Path subPath = new Path(schemaPath, "test1");+ fs.mkdirs(subPath);+ Assertions.assertTrue(fs.exists(subPath));++ Throwable exception1 =+ Assertions.assertThrows(+ NonEmptySchemaException.class,+ () -> ops.dropSchema(NameIdentifier.ofSchema("m1", "c1", name), false));+ Assertions.assertEquals(+ "Schema schema20 with location " + schemaPath + " is not empty", exception1.getMessage());++ // Test drop non-empty schema with cascade = true+ ops.dropSchema(NameIdentifier.ofSchema("m1", "c1", name), true);+ Assertions.assertFalse(fs.exists(schemaPath));+ }+ }++ private Schema createSchema(String name, String comment, String catalogPath, String schemaPath)+ throws IOException {+ Map<String, String> props = Maps.newHashMap();+ if (catalogPath != null) {+ props.put(HadoopCatalogPropertiesMetadata.LOCATION, catalogPath);+ }++ try (HadoopCatalogOperations ops = new HadoopCatalogOperations(null, store, idGenerator)) {+ ops.initialize(props);++ NameIdentifier schemaIdent = NameIdentifier.ofSchema("m1", "c1", name);+ Map<String, String> schemaProps = Maps.newHashMap();+ StringIdentifier stringId = StringIdentifier.fromId(idGenerator.nextId());+ schemaProps = Maps.newHashMap(StringIdentifier.newPropertiesWithId(stringId, schemaProps));++ if (schemaPath != null) {+ schemaProps.put(HadoopSchemaPropertiesMetadata.LOCATION, schemaPath);+ }++ return ops.createSchema(schemaIdent, comment, schemaProps);+ }+ }+}diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveCatalogOperations.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveCatalogOperations.javaindex 2395c67d38..92cd1bf6da 100644--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveCatalogOperations.java+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveCatalogOperations.java@@ -61,7 +61,7 @@ class TestHiveCatalogOperations {Map<String, PropertyEntry<?>> propertyEntryMap =hiveCatalogOperations.catalogPropertiesMetadata().propertyEntries();- Assertions.assertEquals(4, propertyEntryMap.size());+ Assertions.assertEquals(5, propertyEntryMap.size());Assertions.assertTrue(propertyEntryMap.containsKey(METASTORE_URIS));Assertions.assertTrue(propertyEntryMap.containsKey(Catalog.PROPERTY_PACKAGE));Assertions.assertTrue(propertyEntryMap.containsKey(CLIENT_POOL_SIZE));diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/BasePropertiesMetadata.java b/core/src/main/java/com/datastrato/gravitino/catalog/BasePropertiesMetadata.javaindex 9fdffe3a83..4598f6a70d 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/BasePropertiesMetadata.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/BasePropertiesMetadata.java@@ -15,6 +15,10 @@ import java.util.Map;public abstract class BasePropertiesMetadata implements PropertiesMetadata {+ // "gravitino.managed.entity" is an internal and reserved property to indicate whether the+ // entity is managed by Gravitino's own store or not.+ public static final String GRAVITINO_MANAGED_ENTITY = "gravitino.managed.entity";+private static final Map<String, PropertyEntry<?>> BASIC_PROPERTY_ENTRIES;private volatile Map<String, PropertyEntry<?>> propertyEntries;@@ -26,6 +30,11 @@ public abstract class BasePropertiesMetadata implements PropertiesMetadata {PropertyEntry.stringReservedPropertyEntry(ID_KEY,"To differentiate the entities created directly by the underlying sources",+ true),+ PropertyEntry.booleanReservedPropertyEntry(+ GRAVITINO_MANAGED_ENTITY,+ "Whether the entity is managed by Gravitino's own store or not",+ false,true));BASIC_PROPERTY_ENTRIES = Maps.uniqueIndex(basicPropertyEntries, PropertyEntry::getName);diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.javaindex 76ed6ff620..59f880cbf2 100644--- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogOperationDispatcher.java@@ -131,11 +131,20 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasMap<String, String> updatedProperties =StringIdentifier.newPropertiesWithId(stringId, properties);- doWithCatalog(- catalogIdent,- c -> c.doWithSchemaOps(s -> s.createSchema(ident, comment, updatedProperties)),- NoSuchCatalogException.class,- SchemaAlreadyExistsException.class);+ Schema createdSchema =+ doWithCatalog(+ catalogIdent,+ c -> c.doWithSchemaOps(s -> s.createSchema(ident, comment, updatedProperties)),+ NoSuchCatalogException.class,+ SchemaAlreadyExistsException.class);++ // If the Schema is maintained by the Gravitino's store, we don't have to store again.+ boolean isManagedSchema = isManagedSchema(createdSchema);+ if (isManagedSchema) {+ return EntityCombinedSchema.of(createdSchema)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdent, createdSchema.properties()));+ }// Retrieve the Schema again to obtain some values generated by underlying catalogSchema schema =@@ -166,7 +175,7 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas// Merge both the metadata from catalog operation and the metadata from entity store.return EntityCombinedSchema.of(schema, schemaEntity)- .withHiddenPropertiesSet(getHiddenTablePropertyNames(catalogIdent, schema.properties()));+ .withHiddenPropertiesSet(getHiddenSchemaPropertyNames(catalogIdent, schema.properties()));}/**@@ -185,6 +194,14 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasc -> c.doWithSchemaOps(s -> s.loadSchema(ident)),NoSuchSchemaException.class);+ // If the Schema is maintained by the Gravitino's store, we don't have to load again.+ boolean isManagedSchema = isManagedSchema(schema);+ if (isManagedSchema) {+ return EntityCombinedSchema.of(schema)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdentifier, schema.properties()));+ }+StringIdentifier stringId = getStringIdFromProperties(schema.properties());// Case 1: The schema is not created by Gravitino.if (stringId == null) {@@ -236,6 +253,14 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNameIdentifier.of(ident.namespace(), tempAlteredSchema.name()))),NoSuchSchemaException.class);+ // If the Schema is maintained by the Gravitino's store, we don't have to alter again.+ boolean isManagedSchema = isManagedSchema(alteredSchema);+ if (isManagedSchema) {+ return EntityCombinedSchema.of(alteredSchema)+ .withHiddenPropertiesSet(+ getHiddenSchemaPropertyNames(catalogIdent, alteredSchema.properties()));+ }+StringIdentifier stringId = getStringIdFromProperties(alteredSchema.properties());// Case 1: The schema is not created by Gravitino.if (stringId == null) {@@ -294,12 +319,10 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas}try {- store.delete(ident, SCHEMA, cascade);+ return store.delete(ident, SCHEMA, cascade);} catch (Exception e) {throw new RuntimeException(e);}-- return true;}/**@@ -767,6 +790,13 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasreturn NameIdentifier.of(allElems.get(0), allElems.get(1));}+ private boolean isManagedSchema(Schema schema) {+ return schema+ .properties()+ .getOrDefault(BasePropertiesMetadata.GRAVITINO_MANAGED_ENTITY, Boolean.FALSE.toString())+ .equals(Boolean.TRUE.toString());+ }+private static final class FormattedErrorMessages {static final String STORE_OP_FAILURE ="Failed to {} entity for {} in "diff --git a/settings.gradle.kts b/settings.gradle.ktsindex e94bd27567..14d792e5f8 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -13,7 +13,7 @@ include("catalogs:bundled-catalog")include("catalogs:catalog-hive")include("catalogs:catalog-lakehouse-iceberg")include("catalogs:catalog-jdbc-common", "catalogs:catalog-jdbc-mysql", "catalogs:catalog-jdbc-postgresql")-include("catalogs:catalog-fileset")+include("catalogs:catalog-hadoop")include("clients:client-java", "clients:client-java-runtime")include("trino-connector")include("web")