World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1244] feat(API, meta): Add basic API and metadata design for file catalog (#1487)
Jerry Shaof0129d46e46b
diff --git a/api/src/main/java/com/datastrato/gravitino/exceptions/FilesetAlreadyExistsException.java b/api/src/main/java/com/datastrato/gravitino/exceptions/FilesetAlreadyExistsException.javanew file mode 100644index 0000000000..83f44f7d47--- /dev/null+++ b/api/src/main/java/com/datastrato/gravitino/exceptions/FilesetAlreadyExistsException.java@@ -0,0 +1,17 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.exceptions;++/** Exception thrown when a file with specified name already exists. */+public class FilesetAlreadyExistsException extends AlreadyExistsException {++ public FilesetAlreadyExistsException(String message) {+ super(message);+ }++ public FilesetAlreadyExistsException(String message, Throwable cause) {+ super(message, cause);+ }+}diff --git a/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchFilesetException.java b/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchFilesetException.javanew file mode 100644index 0000000000..fb24897f96--- /dev/null+++ b/api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchFilesetException.java@@ -0,0 +1,17 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.exceptions;++/** Exception thrown when a file with specified name is not existed. */+public class NoSuchFilesetException extends NotFoundException {++ public NoSuchFilesetException(String message) {+ super(message);+ }++ public NoSuchFilesetException(String message, Throwable cause) {+ super(message, cause);+ }+}diff --git a/api/src/main/java/com/datastrato/gravitino/file/Fileset.java b/api/src/main/java/com/datastrato/gravitino/file/Fileset.javanew file mode 100644index 0000000000..88ffe9d677--- /dev/null+++ b/api/src/main/java/com/datastrato/gravitino/file/Fileset.java@@ -0,0 +1,59 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.file;++import com.datastrato.gravitino.Auditable;+import com.datastrato.gravitino.Namespace;+import java.util.Collections;+import java.util.Map;+import javax.annotation.Nullable;++/**+ * An interface representing a fileset under a schema {@link Namespace}. A fileset is a virtual+ * concept of the file or directory that is managed by Gravitino. Users can create a fileset object+ * to manage the non-tabular data on the FS-like storage. The typical use case is to manage the+ * training data for AI workloads. The major difference compare to the relational table is that the+ * fileset is schema-free, the main property of the fileset is the storage location of the+ * underlying data.+ *+ * <p>{@link Fileset} defines the basic properties of a fileset object. A catalog implementation+ * with {@link FilesetCatalog} should implement this interface.+ */+public interface Fileset extends Auditable {++ /** An enum representing the type of the fileset object. */+ enum Type {+ MANAGED, // Fileset is managed by Gravitino. When specified, the data will be deleted when the+ // fileset object is deleted.+ EXTERNAL // Fileset is not managed by Gravitino. When specified, the data will not be deleted+ // when the fileset object is deleted.+ }++ /** @return Name of the fileset object. */+ String name();++ /** @return The comment of the fileset object. Null is returned if no comment is set. */+ @Nullable+ default String comment() {+ return null;+ }++ /** @return The type of the fileset object. */+ Type type();++ /**+ * Get the storage location of the file or directory path that is managed by this fileset object.+ *+ * @return The storage location of the fileset object.+ */+ String storageLocation();++ /**+ * @return The properties of the fileset object. Empty map is returned if no properties are set.+ */+ default Map<String, String> properties() {+ return Collections.emptyMap();+ }+}diff --git a/api/src/main/java/com/datastrato/gravitino/file/FilesetCatalog.java b/api/src/main/java/com/datastrato/gravitino/file/FilesetCatalog.javanew file mode 100644index 0000000000..3054ea1451--- /dev/null+++ b/api/src/main/java/com/datastrato/gravitino/file/FilesetCatalog.java@@ -0,0 +1,103 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.file;++import com.datastrato.gravitino.NameIdentifier;+import com.datastrato.gravitino.Namespace;+import com.datastrato.gravitino.exceptions.FilesetAlreadyExistsException;+import com.datastrato.gravitino.exceptions.NoSuchFilesetException;+import com.datastrato.gravitino.exceptions.NoSuchSchemaException;+import java.util.Map;++/**+ * The FilesetCatalog interface defines the public API for managing fileset objects in a schema. If+ * the catalog implementation supports fileset objects, it should implement this interface.+ */+public interface FilesetCatalog {++ /**+ * List the filesets in a schema namespace from the catalog.+ *+ * @param namespace A schema namespace.+ * @return An array of fileset identifiers in the namespace.+ * @throws NoSuchSchemaException If the schema does not exist.+ */+ NameIdentifier[] listFilesets(Namespace namespace) throws NoSuchSchemaException;++ /**+ * Load fileset metadata by {@link NameIdentifier} from the catalog.+ *+ * @param ident A fileset identifier.+ * @return The fileset metadata.+ * @throws NoSuchFilesetException If the fileset does not exist.+ */+ Fileset loadFileset(NameIdentifier ident) throws NoSuchFilesetException;++ /**+ * Check if a fileset exists using an {@link NameIdentifier} from the catalog.+ *+ * @param ident A fileset identifier.+ * @return true If the fileset exists, false otherwise.+ */+ default boolean filesetExists(NameIdentifier ident) {+ try {+ loadFileset(ident);+ return true;+ } catch (NoSuchFilesetException e) {+ return false;+ }+ }++ /**+ * Create a fileset metadata in the catalog.+ *+ * <p>If the type of the fileset object is "MANAGED", the underlying storageLocation can be null,+ * and Gravitino will manage the storage location based on the location of the schema.+ *+ * <p>If the type of the fileset object is "EXTERNAL", the underlying storageLocation must be set.+ *+ * @param ident A fileset identifier.+ * @param comment The comment of the fileset.+ * @param type The type of the fileset.+ * @param storageLocation The storage location of the fileset.+ * @param properties The properties of the fileset.+ * @return The created fileset metadata+ * @throws NoSuchSchemaException If the schema does not exist.+ * @throws FilesetAlreadyExistsException If the fileset already exists.+ */+ Fileset createFileset(+ NameIdentifier ident,+ String comment,+ Fileset.Type type,+ String storageLocation,+ Map<String, String> properties)+ throws NoSuchSchemaException, FilesetAlreadyExistsException;++ /**+ * Apply the {@link FilesetChange change} to a fileset in the catalog.+ *+ * <p>Implementation may reject the change. If any change is rejected, no changes should be+ * applied to the fileset.+ *+ * @param ident A fileset identifier.+ * @param changes The changes to apply to the fileset.+ * @return The altered fileset metadata.+ * @throws NoSuchFilesetException If the fileset does not exist.+ * @throws IllegalArgumentException If the change is rejected by the implementation.+ */+ Fileset alterFileset(NameIdentifier ident, FilesetChange... changes)+ throws NoSuchFilesetException, IllegalArgumentException;++ /**+ * Drop a fileset from the catalog.+ *+ * <p>The underlying files will be deleted if this fileset type is managed, otherwise, only the+ * metadata will be dropped.+ *+ * @param ident A fileset identifier.+ * @return true If the fileset is dropped, false the fileset did not exist.+ */+ boolean dropFileset(NameIdentifier ident);+}diff --git a/api/src/main/java/com/datastrato/gravitino/file/FilesetChange.java b/api/src/main/java/com/datastrato/gravitino/file/FilesetChange.javanew file mode 100644index 0000000000..570421cf12--- /dev/null+++ b/api/src/main/java/com/datastrato/gravitino/file/FilesetChange.java@@ -0,0 +1,287 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.file;++import java.util.Objects;++/**+ * A fileset change is a change to a fileset. It can be used to rename a fileset, update the comment+ * of a fileset, set a property and value pair for a fileset, or remove a property from a fileset.+ */+public interface FilesetChange {++ /**+ * Creates a new fileset change to rename the fileset.+ *+ * @param newName The new name of the fileset.+ * @return The fileset change.+ */+ static FilesetChange rename(String newName) {+ return new RenameFileset(newName);+ }++ /**+ * Creates a new fileset change to update the fileset comment.+ *+ * @param newComment The new comment for the fileset.+ * @return The fileset change.+ */+ static FilesetChange updateComment(String newComment) {+ return new UpdateFilesetComment(newComment);+ }++ /**+ * Creates a new fileset change to set the property and value for the fileset.+ *+ * @param property The property name to set.+ * @param value The value to set the property to.+ * @return The fileset change.+ */+ static FilesetChange setProperty(String property, String value) {+ return new SetProperty(property, value);+ }++ /**+ * Creates a new fileset change to remove a property from the fileset.+ *+ * @param property The property name to remove.+ * @return The fileset change.+ */+ static FilesetChange removeProperty(String property) {+ return new RemoveProperty(property);+ }++ /** A fileset change to rename the fileset. */+ final class RenameFileset implements FilesetChange {+ private final String newName;++ private RenameFileset(String newName) {+ this.newName = newName;+ }++ /**+ * Retrieves the new name set for the fileset.+ *+ * @return The new name of the fileset.+ */+ public String getNewName() {+ return newName;+ }++ /**+ * Compares this RenameFileset instance with another object for equality. Two instances are+ * considered equal if they designate the same new name for the fileset.+ *+ * @param o The object to compare with this instance.+ * @return true if the given object represents an identical fileset renaming operation; false+ * otherwise.+ */+ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ RenameFileset that = (RenameFileset) o;+ return Objects.equals(newName, that.newName);+ }++ /**+ * Generates a hash code for this RenameFileset instance. The hash code is primarily based on+ * the new name for the fileset.+ *+ * @return A hash code value for this renaming operation.+ */+ @Override+ public int hashCode() {+ return Objects.hash(newName);+ }++ /**+ * Provides a string representation of the RenameFile instance. This string includes the class+ * name followed by the new name of the fileset.+ *+ * @return A string summary of this renaming operation.+ */+ @Override+ public String toString() {+ return "RENAMEFILESET " + newName;+ }+ }++ /** A fileset change to update the fileset comment. */+ final class UpdateFilesetComment implements FilesetChange {+ private final String newComment;++ private UpdateFilesetComment(String newComment) {+ this.newComment = newComment;+ }++ /**+ * Retrieves the new comment intended for the fileset.+ *+ * @return The new comment that has been set for the fileset.+ */+ public String getNewComment() {+ return newComment;+ }++ /**+ * Compares this UpdateFilesetComment instance with another object for equality. Two instances+ * are considered equal if they designate the same new comment for the fileset.+ *+ * @param o The object to compare with this instance.+ * @return true if the given object represents the same comment update; false otherwise.+ */+ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ UpdateFilesetComment that = (UpdateFilesetComment) o;+ return Objects.equals(newComment, that.newComment);+ }++ /**+ * Generates a hash code for this UpdateFileComment instance. The hash code is based on the new+ * comment for the fileset.+ *+ * @return A hash code representing this comment update operation.+ */+ @Override+ public int hashCode() {+ return Objects.hash(newComment);+ }++ /**+ * Provides a string representation of the UpdateFilesetComment instance. This string format+ * includes the class name followed by the new comment for the fileset.+ *+ * @return A string summary of this comment update operation.+ */+ @Override+ public String toString() {+ return "UPDATEFILESETCOMMENT " + newComment;+ }+ }++ /** A fileset change to set the property and value for the fileset. */+ final class SetProperty implements FilesetChange {+ private final String property;+ private final String value;++ private SetProperty(String property, String value) {+ this.property = property;+ this.value = value;+ }++ /**+ * Retrieves the name of the property being set in the fileset.+ *+ * @return The name of the property.+ */+ public String getProperty() {+ return property;+ }++ /**+ * Retrieves the value assigned to the property in the fileset.+ *+ * @return The value of the property.+ */+ public String getValue() {+ return value;+ }++ /**+ * Compares this SetProperty instance with another object for equality. Two instances are+ * considered equal if they have the same property and value for the fileset.+ *+ * @param o The object to compare with this instance.+ * @return true if the given object represents the same property setting; false otherwise.+ */+ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ SetProperty that = (SetProperty) o;+ return Objects.equals(property, that.property) && Objects.equals(value, that.value);+ }++ /**+ * Generates a hash code for this SetProperty instance. The hash code is based on both the+ * property name and its assigned value.+ *+ * @return A hash code value for this property setting.+ */+ @Override+ public int hashCode() {+ return Objects.hash(property, value);+ }++ /**+ * Provides a string representation of the SetProperty instance. This string format includes the+ * class name followed by the property and its value.+ *+ * @return A string summary of the property setting.+ */+ @Override+ public String toString() {+ return "SETPROPERTY " + property + " " + value;+ }+ }++ /** A fileset change to remove a property from the fileset. */+ final class RemoveProperty implements FilesetChange {+ private final String property;++ private RemoveProperty(String property) {+ this.property = property;+ }++ /**+ * Retrieves the name of the property to be removed from the fileset.+ *+ * @return The name of the property for removal.+ */+ public String getProperty() {+ return property;+ }++ /**+ * Compares this RemoveProperty instance with another object for equality. Two instances are+ * considered equal if they target the same property for removal from the fileset.+ *+ * @param o The object to compare with this instance.+ * @return true if the given object represents the same property removal; false otherwise.+ */+ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ RemoveProperty that = (RemoveProperty) o;+ return Objects.equals(property, that.property);+ }++ /**+ * Generates a hash code for this RemoveProperty instance. The hash code is based on the+ * property name that is to be removed from the fileset.+ *+ * @return A hash code value for this property removal operation.+ */+ @Override+ public int hashCode() {+ return Objects.hash(property);+ }++ /**+ * Provides a string representation of the RemoveProperty instance. This string format includes+ * the class name followed by the property name to be removed.+ *+ * @return A string summary of the property removal operation.+ */+ @Override+ public String toString() {+ return "REMOVEPROPERTY " + property;+ }+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/Entity.java b/core/src/main/java/com/datastrato/gravitino/Entity.javaindex 3d37b7ef65..8d5ec9b259 100644--- a/core/src/main/java/com/datastrato/gravitino/Entity.java+++ b/core/src/main/java/com/datastrato/gravitino/Entity.java@@ -19,6 +19,7 @@ public interface Entity extends Serializable {SCHEMA("sc", 2),TABLE("ta", 3),COLUMN("co", 4),+ FILESET("fi", 5),AUDIT("au", 65534);diff --git a/core/src/main/java/com/datastrato/gravitino/meta/FilesetEntity.java b/core/src/main/java/com/datastrato/gravitino/meta/FilesetEntity.javanew file mode 100644index 0000000000..7f0ccdfd88--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/meta/FilesetEntity.java@@ -0,0 +1,271 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.meta;++import com.datastrato.gravitino.Auditable;+import com.datastrato.gravitino.Entity;+import com.datastrato.gravitino.Field;+import com.datastrato.gravitino.HasIdentifier;+import com.datastrato.gravitino.file.Fileset;+import com.google.common.collect.Maps;+import java.util.Collections;+import java.util.Map;+import java.util.Objects;+import javax.annotation.Nullable;+import lombok.ToString;++@ToString+public class FilesetEntity implements Entity, Auditable, HasIdentifier {++ public static final Field ID =+ Field.required("id", Long.class, "The unique id of the fileset entity.");+ public static final Field NAME =+ Field.required("name", String.class, "The name of the fileset entity.");+ public static final Field COMMENT =+ Field.optional("comment", String.class, "The comment or description of the fileset entity.");+ public static final Field TYPE =+ Field.required("type", Fileset.Type.class, "The type of the fileset entity.");+ public static final Field STORAGE_LOCATION =+ Field.optional(+ "storage_location", String.class, "The storage location of the fileset entity.");+ public static final Field AUDIT_INFO =+ Field.required("audit_info", AuditInfo.class, "The audit details of the fileset entity.");+ public static final Field PROPERTIES =+ Field.optional("properties", Map.class, "The properties of the fileset entity.");++ private Long id;++ private String name;++ private String comment;++ private Fileset.Type type;++ @Nullable private String storageLocation;++ private AuditInfo auditInfo;++ private Map<String, String> properties;++ private FilesetEntity() {}++ /**+ * Returns a map of fields and their corresponding values for this fileset entity.+ *+ * @return An unmodifiable map of the fields and values.+ */+ @Override+ public Map<Field, Object> fields() {+ Map<Field, Object> fields = Maps.newHashMap();+ fields.put(ID, id);+ fields.put(NAME, name);+ fields.put(COMMENT, comment);+ fields.put(TYPE, type);+ fields.put(STORAGE_LOCATION, storageLocation);+ fields.put(AUDIT_INFO, auditInfo);+ fields.put(PROPERTIES, properties);++ return Collections.unmodifiableMap(fields);+ }++ /**+ * Returns the name of the fileset entity.+ *+ * @return The name of the fileset entity.+ */+ @Override+ public String name() {+ return name;+ }++ /**+ * Returns the unique id of the fileset entity.+ *+ * @return The unique id of the fileset entity.+ */+ @Override+ public Long id() {+ return id;+ }++ /**+ * Returns the audit details of the fileset entity.+ *+ * @return The audit details of the fileset entity.+ */+ @Override+ public AuditInfo auditInfo() {+ return auditInfo;+ }++ /**+ * Returns the type of the entity.+ *+ * @return The type of the entity.+ */+ @Override+ public EntityType type() {+ return EntityType.FILESET;+ }++ /**+ * Returns the comment of the fileset entity.+ *+ * @return The comment of the fileset entity.+ */+ public String comment() {+ return comment;+ }++ /**+ * Returns the type of the fileset entity.+ *+ * @return The type of the fileset entity.+ */+ public Fileset.Type filesetType() {+ return type;+ }++ /**+ * Returns the storage location of the fileset entity.+ *+ * @return The storage location of the fileset entity.+ */+ public String storageLocation() {+ return storageLocation;+ }++ /**+ * Returns the properties of the fileset entity.+ *+ * @return The properties of the fileset entity.+ */+ public Map<String, String> properties() {+ return properties;+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (!(o instanceof FilesetEntity)) return false;++ FilesetEntity that = (FilesetEntity) o;+ return Objects.equals(id, that.id)+ && Objects.equals(name, that.name)+ && Objects.equals(comment, that.comment)+ && Objects.equals(type, that.type)+ && Objects.equals(storageLocation, that.storageLocation)+ && Objects.equals(auditInfo, that.auditInfo)+ && Objects.equals(properties, that.properties);+ }++ @Override+ public int hashCode() {+ return Objects.hash(id, name, comment, type, storageLocation, auditInfo, properties);+ }++ public static class Builder {++ private final FilesetEntity fileset;++ public Builder() {+ fileset = new FilesetEntity();+ }++ /**+ * Sets the unique id of the fileset entity.+ *+ * @param id The unique id of the fileset entity.+ * @return The builder instance.+ */+ public Builder withId(Long id) {+ fileset.id = id;+ return this;+ }++ /**+ * Sets the name of the fileset entity.+ *+ * @param name The name of the fileset entity.+ * @return The builder instance.+ */+ public Builder withName(String name) {+ fileset.name = name;+ return this;+ }++ /**+ * Sets the comment of the fileset entity.+ *+ * @param comment The comment of the fileset entity.+ * @return The builder instance.+ */+ public Builder withComment(String comment) {+ fileset.comment = comment;+ return this;+ }++ /**+ * Sets the type of the fileset entity.+ *+ * @param type The type of the fileset entity.+ * @return The builder instance.+ */+ public Builder withFilesetType(Fileset.Type type) {+ fileset.type = type;+ return this;+ }++ /**+ * Sets the storage location of the fileset entity.+ *+ * <p>Only the EXTERNAL type of fileset entity requires a storage location.+ *+ * @param storageLocation The storage location of the fileset entity.+ * @return The builder instance.+ */+ public Builder withStorageLocation(String storageLocation) {+ fileset.storageLocation = storageLocation;+ return this;+ }++ /**+ * Sets the audit details of the fileset entity.+ *+ * @param auditInfo The audit details of the fileset entity.+ * @return The builder instance.+ */+ public Builder withAuditInfo(AuditInfo auditInfo) {+ fileset.auditInfo = auditInfo;+ return this;+ }++ /**+ * Sets the properties of the fileset entity.+ *+ * @param properties The properties of the fileset entity.+ * @return The builder instance.+ */+ public Builder withProperties(Map<String, String> properties) {+ fileset.properties = properties;+ return this;+ }++ /**+ * Builds the fileset entity.+ *+ * @return The fileset entity.+ */+ public FilesetEntity build() {+ fileset.validate();++ if (fileset.type == Fileset.Type.EXTERNAL && fileset.storageLocation == null) {+ throw new IllegalArgumentException("Storage location is required for EXTERNAL fileset.");+ }++ return fileset;+ }+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/meta/SchemaEntity.java b/core/src/main/java/com/datastrato/gravitino/meta/SchemaEntity.javaindex ca7b37aecf..932643d3e9 100644--- a/core/src/main/java/com/datastrato/gravitino/meta/SchemaEntity.java+++ b/core/src/main/java/com/datastrato/gravitino/meta/SchemaEntity.java@@ -23,15 +23,23 @@ public class SchemaEntity implements Entity, Auditable, HasIdentifier {public static final Field NAME = Field.required("name", String.class, "The schema's name");public static final Field AUDIT_INFO =Field.required("audit_info", AuditInfo.class, "The audit details of the schema");+ public static final Field COMMENT =+ Field.optional("comment", String.class, "The comment or description of the schema");+ public static final Field PROPERTIES =+ Field.optional("properties", Map.class, "The properties of the schema");private Long id;private String name;+ private String comment;+private AuditInfo auditInfo;protected Namespace namespace;+ private Map<String, String> properties;+/*** Returns an unmodifiable map of the fields and their corresponding values for this schema.*@@ -43,6 +51,8 @@ public class SchemaEntity implements Entity, Auditable, HasIdentifier {fields.put(ID, id);fields.put(NAME, name);fields.put(AUDIT_INFO, auditInfo);+ fields.put(COMMENT, comment);+ fields.put(PROPERTIES, properties);return Collections.unmodifiableMap(fields);}@@ -87,6 +97,26 @@ public class SchemaEntity implements Entity, Auditable, HasIdentifier {return auditInfo;}+ /**+ * Returns the comment of the schema. The returned string can be null if it is not stored in the+ * Gravitino storage.+ *+ * @return The comment of the schema.+ */+ public String comment() {+ return comment;+ }++ /**+ * Return the properties of the schema. The returned map can be null if it is not stored in the+ * Gravitino storage.+ *+ * @return The properties of the schema.+ */+ public Map<String, String> properties() {+ return properties;+ }+/*** Returns the type of the entity, which is {@link EntityType#SCHEMA}.*@@ -109,12 +139,14 @@ public class SchemaEntity implements Entity, Auditable, HasIdentifier {SchemaEntity schema = (SchemaEntity) o;return Objects.equal(id, schema.id)&& Objects.equal(name, schema.name)+ && Objects.equal(comment, schema.comment)+ && Objects.equal(properties, schema.properties)&& Objects.equal(auditInfo, schema.auditInfo);}@Overridepublic int hashCode() {- return Objects.hashCode(id, name, auditInfo);+ return Objects.hashCode(id, name, auditInfo, comment, properties);}/** A builder class for {@link SchemaEntity}. */@@ -159,6 +191,28 @@ public class SchemaEntity implements Entity, Auditable, HasIdentifier {return this;}+ /**+ * Sets the comment of the schema.+ *+ * @param comment The comment of the schema.+ * @return The builder instance.+ */+ public Builder withComment(String comment) {+ schema.comment = comment;+ return this;+ }++ /**+ * Sets the properties of the schema.+ *+ * @param properties The properties of the schema.+ * @return The builder instance.+ */+ public Builder withProperties(Map<String, String> properties) {+ schema.properties = properties;+ return this;+ }+/*** Sets the audit details of the schema.*diff --git a/core/src/main/java/com/datastrato/gravitino/proto/FilesetEntitySerDe.java b/core/src/main/java/com/datastrato/gravitino/proto/FilesetEntitySerDe.javanew file mode 100644index 0000000000..f66272ab2a--- /dev/null+++ b/core/src/main/java/com/datastrato/gravitino/proto/FilesetEntitySerDe.java@@ -0,0 +1,60 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */+package com.datastrato.gravitino.proto;++import com.datastrato.gravitino.meta.FilesetEntity;++public class FilesetEntitySerDe implements ProtoSerDe<FilesetEntity, Fileset> {+ @Override+ public Fileset serialize(FilesetEntity filesetEntity) {+ Fileset.Builder builder =+ Fileset.newBuilder()+ .setId(filesetEntity.id())+ .setName(filesetEntity.name())+ .setAuditInfo(new AuditInfoSerDe().serialize(filesetEntity.auditInfo()));++ if (filesetEntity.comment() != null) {+ builder.setComment(filesetEntity.comment());+ }++ if (filesetEntity.properties() != null && !filesetEntity.properties().isEmpty()) {+ builder.putAllProperties(filesetEntity.properties());+ }++ Fileset.Type type = Fileset.Type.valueOf(filesetEntity.filesetType().name());+ builder.setType(type);++ if (filesetEntity.storageLocation() != null) {+ builder.setStorageLocation(filesetEntity.storageLocation());+ }++ return builder.build();+ }++ @Override+ public FilesetEntity deserialize(Fileset p) {+ FilesetEntity.Builder builder =+ new FilesetEntity.Builder()+ .withId(p.getId())+ .withName(p.getName())+ .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()))+ .withFilesetType(+ com.datastrato.gravitino.file.Fileset.Type.valueOf(p.getType().name()));++ if (p.hasComment()) {+ builder.withComment(p.getComment());+ }++ if (p.hasStorageLocation()) {+ builder.withStorageLocation(p.getStorageLocation());+ }++ if (p.getPropertiesCount() > 0) {+ builder.withProperties(p.getPropertiesMap());+ }++ return builder.build();+ }+}diff --git a/core/src/main/java/com/datastrato/gravitino/proto/ProtoEntitySerDe.java b/core/src/main/java/com/datastrato/gravitino/proto/ProtoEntitySerDe.javaindex 0026e6df91..646a0e3ed7 100644--- a/core/src/main/java/com/datastrato/gravitino/proto/ProtoEntitySerDe.java+++ b/core/src/main/java/com/datastrato/gravitino/proto/ProtoEntitySerDe.java@@ -33,7 +33,10 @@ public class ProtoEntitySerDe implements EntitySerDe {"com.datastrato.gravitino.proto.SchemaEntitySerDe").put("com.datastrato.gravitino.meta.TableEntity",- "com.datastrato.gravitino.proto.TableEntitySerde")+ "com.datastrato.gravitino.proto.TableEntitySerDe")+ .put(+ "com.datastrato.gravitino.meta.FilesetEntity",+ "com.datastrato.gravitino.proto.FilesetEntitySerDe").build();private static final Map<String, String> ENTITY_TO_PROTO =@@ -47,7 +50,9 @@ public class ProtoEntitySerDe implements EntitySerDe {"com.datastrato.gravitino.meta.SchemaEntity","com.datastrato.gravitino.proto.Schema","com.datastrato.gravitino.meta.TableEntity",- "com.datastrato.gravitino.proto.Table");+ "com.datastrato.gravitino.proto.Table",+ "com.datastrato.gravitino.meta.FilesetEntity",+ "com.datastrato.gravitino.proto.Fileset");private final Map<Class<? extends Entity>, ProtoSerDe<? extends Entity, ? extends Message>>entityToSerDe;diff --git a/core/src/main/java/com/datastrato/gravitino/proto/SchemaEntitySerDe.java b/core/src/main/java/com/datastrato/gravitino/proto/SchemaEntitySerDe.javaindex 193a7895b2..ee64e6945e 100644--- a/core/src/main/java/com/datastrato/gravitino/proto/SchemaEntitySerDe.java+++ b/core/src/main/java/com/datastrato/gravitino/proto/SchemaEntitySerDe.java@@ -9,19 +9,39 @@ import com.datastrato.gravitino.meta.SchemaEntity;public class SchemaEntitySerDe implements ProtoSerDe<SchemaEntity, Schema> {@Overridepublic Schema serialize(SchemaEntity schemaEntity) {- return Schema.newBuilder()- .setId(schemaEntity.id())- .setName(schemaEntity.name())- .setAuditInfo(new AuditInfoSerDe().serialize(schemaEntity.auditInfo()))- .build();+ Schema.Builder builder =+ Schema.newBuilder()+ .setId(schemaEntity.id())+ .setName(schemaEntity.name())+ .setAuditInfo(new AuditInfoSerDe().serialize(schemaEntity.auditInfo()));++ if (schemaEntity.comment() != null) {+ builder.setComment(schemaEntity.comment());+ }++ if (schemaEntity.properties() != null && !schemaEntity.properties().isEmpty()) {+ builder.putAllProperties(schemaEntity.properties());+ }++ return builder.build();}@Overridepublic SchemaEntity deserialize(Schema p) {- return new SchemaEntity.Builder()- .withId(p.getId())- .withName(p.getName())- .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()))- .build();+ SchemaEntity.Builder builder =+ new SchemaEntity.Builder()+ .withId(p.getId())+ .withName(p.getName())+ .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()));++ if (p.hasComment()) {+ builder.withComment(p.getComment());+ }++ if (p.getPropertiesCount() > 0) {+ builder.withProperties(p.getPropertiesMap());+ }++ return builder.build();}}diff --git a/core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerde.java b/core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerDe.javasimilarity index 91%rename from core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerde.javarename to core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerDe.javaindex a4b17b8b5c..15a061ad7e 100644--- a/core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerde.java+++ b/core/src/main/java/com/datastrato/gravitino/proto/TableEntitySerDe.java@@ -6,7 +6,7 @@ package com.datastrato.gravitino.proto;import com.datastrato.gravitino.meta.TableEntity;-public class TableEntitySerde implements ProtoSerDe<TableEntity, Table> {+public class TableEntitySerDe implements ProtoSerDe<TableEntity, Table> {@Overridepublic Table serialize(TableEntity tableEntity) {return Table.newBuilder()diff --git a/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java b/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.javaindex ff13d055c4..4924205271 100644--- a/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java+++ b/core/src/test/java/com/datastrato/gravitino/meta/TestEntity.java@@ -6,6 +6,7 @@ package com.datastrato.gravitino.meta;import com.datastrato.gravitino.Catalog;import com.datastrato.gravitino.Field;+import com.datastrato.gravitino.file.Fileset;import com.google.common.collect.ImmutableMap;import java.time.Instant;import java.util.Map;@@ -38,6 +39,10 @@ public class TestEntity {private final Long tableId = 1L;private final String tableName = "testTable";+ // File test data+ private final Long fileId = 1L;+ private final String fileName = "testFile";+@Testpublic void testMetalake() {BaseMetalake metalake =@@ -94,6 +99,18 @@ public class TestEntity {Assertions.assertEquals(schemaId, fields.get(SchemaEntity.ID));Assertions.assertEquals(schemaName, fields.get(SchemaEntity.NAME));Assertions.assertEquals(auditInfo, fields.get(SchemaEntity.AUDIT_INFO));++ SchemaEntity testSchema1 =+ new SchemaEntity.Builder()+ .withId(schemaId)+ .withName(schemaName)+ .withAuditInfo(auditInfo)+ .withComment("testComment")+ .withProperties(map)+ .build();+ Map<Field, Object> fields1 = testSchema1.fields();+ Assertions.assertEquals("testComment", fields1.get(SchemaEntity.COMMENT));+ Assertions.assertEquals(map, fields1.get(SchemaEntity.PROPERTIES));}@Test@@ -110,4 +127,53 @@ public class TestEntity {Assertions.assertEquals(tableName, fields.get(TableEntity.NAME));Assertions.assertEquals(auditInfo, fields.get(TableEntity.AUDIT_INFO));}++ @Test+ public void testFile() {+ FilesetEntity testFile =+ new FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(Fileset.Type.MANAGED)+ .withProperties(map)+ .build();++ Map<Field, Object> fields = testFile.fields();+ Assertions.assertEquals(fileId, fields.get(FilesetEntity.ID));+ Assertions.assertEquals(fileName, fields.get(FilesetEntity.NAME));+ Assertions.assertEquals(auditInfo, fields.get(FilesetEntity.AUDIT_INFO));+ Assertions.assertEquals(Fileset.Type.MANAGED, fields.get(FilesetEntity.TYPE));+ Assertions.assertEquals(map, fields.get(FilesetEntity.PROPERTIES));+ Assertions.assertNull(fields.get(FilesetEntity.COMMENT));++ FilesetEntity testFile1 =+ new FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(Fileset.Type.MANAGED)+ .withProperties(map)+ .withComment("testComment")+ .withStorageLocation("testLocation")+ .build();+ Assertions.assertEquals("testComment", testFile1.comment());+ Assertions.assertEquals("testLocation", testFile1.storageLocation());++ Throwable exception =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> {+ new FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(Fileset.Type.EXTERNAL)+ .withProperties(map)+ .withComment("testComment")+ .build();+ });+ Assertions.assertEquals(+ "Storage location is required for EXTERNAL fileset.", exception.getMessage());+ }}diff --git a/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java b/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.javaindex dc4f44afb1..65b4ca3b57 100644--- a/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java+++ b/core/src/test/java/com/datastrato/gravitino/proto/TestEntityProtoSerDe.java@@ -147,6 +147,23 @@ public class TestEntityProtoSerDe {protoEntitySerDe.deserialize(schemaBytes, com.datastrato.gravitino.meta.SchemaEntity.class);Assertions.assertEquals(schemaEntity, schemaEntityFromBytes);+ // Test SchemaEntity with additional fields+ com.datastrato.gravitino.meta.SchemaEntity schemaEntity1 =+ new com.datastrato.gravitino.meta.SchemaEntity.Builder()+ .withId(schemaId)+ .withName(schemaName)+ .withAuditInfo(auditInfo)+ .withComment(comment)+ .withProperties(props)+ .build();+ byte[] schemaBytes1 = protoEntitySerDe.serialize(schemaEntity1);+ com.datastrato.gravitino.meta.SchemaEntity schemaEntityFromBytes1 =+ protoEntitySerDe.deserialize(+ schemaBytes1, com.datastrato.gravitino.meta.SchemaEntity.class);+ Assertions.assertEquals(schemaEntity1, schemaEntityFromBytes1);+ Assertions.assertEquals(comment, schemaEntityFromBytes1.comment());+ Assertions.assertEquals(props, schemaEntityFromBytes1.properties());+// Test TableEntityLong tableId = 1L;String tableName = "table";@@ -161,5 +178,55 @@ public class TestEntityProtoSerDe {com.datastrato.gravitino.meta.TableEntity tableEntityFromBytes =protoEntitySerDe.deserialize(tableBytes, com.datastrato.gravitino.meta.TableEntity.class);Assertions.assertEquals(tableEntity, tableEntityFromBytes);++ // Test FileEntity+ Long fileId = 1L;+ String fileName = "file";+ com.datastrato.gravitino.meta.FilesetEntity fileEntity =+ new com.datastrato.gravitino.meta.FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(com.datastrato.gravitino.file.Fileset.Type.MANAGED)+ .withProperties(props)+ .withComment(comment)+ .build();+ byte[] fileBytes = protoEntitySerDe.serialize(fileEntity);+ com.datastrato.gravitino.meta.FilesetEntity fileEntityFromBytes =+ protoEntitySerDe.deserialize(fileBytes, com.datastrato.gravitino.meta.FilesetEntity.class);+ Assertions.assertEquals(fileEntity, fileEntityFromBytes);++ com.datastrato.gravitino.meta.FilesetEntity fileEntity1 =+ new com.datastrato.gravitino.meta.FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(com.datastrato.gravitino.file.Fileset.Type.MANAGED)+ .build();+ byte[] fileBytes1 = protoEntitySerDe.serialize(fileEntity1);+ com.datastrato.gravitino.meta.FilesetEntity fileEntityFromBytes1 =+ protoEntitySerDe.deserialize(fileBytes1, com.datastrato.gravitino.meta.FilesetEntity.class);+ Assertions.assertEquals(fileEntity1, fileEntityFromBytes1);+ Assertions.assertNull(fileEntityFromBytes1.comment());+ Assertions.assertNull(fileEntityFromBytes1.properties());+ Assertions.assertNull(fileEntityFromBytes1.storageLocation());++ com.datastrato.gravitino.meta.FilesetEntity fileEntity2 =+ new com.datastrato.gravitino.meta.FilesetEntity.Builder()+ .withId(fileId)+ .withName(fileName)+ .withAuditInfo(auditInfo)+ .withFilesetType(com.datastrato.gravitino.file.Fileset.Type.EXTERNAL)+ .withProperties(props)+ .withComment(comment)+ .withStorageLocation("testLocation")+ .build();+ byte[] fileBytes2 = protoEntitySerDe.serialize(fileEntity2);+ com.datastrato.gravitino.meta.FilesetEntity fileEntityFromBytes2 =+ protoEntitySerDe.deserialize(fileBytes2, com.datastrato.gravitino.meta.FilesetEntity.class);+ Assertions.assertEquals(fileEntity2, fileEntityFromBytes2);+ Assertions.assertEquals("testLocation", fileEntityFromBytes2.storageLocation());+ Assertions.assertEquals(+ com.datastrato.gravitino.file.Fileset.Type.EXTERNAL, fileEntityFromBytes2.filesetType());}}diff --git a/meta/src/main/proto/gravitino_meta.proto b/meta/src/main/proto/gravitino_meta.protoindex ec332ad3c3..53639b5333 100644--- a/meta/src/main/proto/gravitino_meta.proto+++ b/meta/src/main/proto/gravitino_meta.proto@@ -61,10 +61,35 @@ message Schema {uint64 id = 1;string name = 2;AuditInfo audit_info = 3;+ // These two fields will be used when the schema object is managed by Gravitino, otherwise, it+ // will be ignored.+ optional string comment = 4;+ map<string, string> properties = 5;}message Table {uint64 id = 1;string name = 2;AuditInfo audit_info = 3;-}\ No newline at end of file+}++/**+ * The Fileset message is used to record the fileset object information. Fileset object represents+ * the non-tabular data on FS-like storage, like HDFS, S3, etc.+ */+message Fileset {+ enum Type {+ MANAGED = 0; // The storage location is managed by Gravitino. When specified, the data will be+ // deleted when the file object is deleted.+ EXTERNAL = 1; // The storage location is managed by user. When specified, the data will not be+ // deleted when the file object is deleted.+ }++ uint64 id = 1;+ string name = 2;+ optional string comment = 3;+ Type type = 4;+ optional string storage_location = 5;+ map<string, string> properties = 6;+ AuditInfo audit_info = 7;+}