Skip to content

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

[#2084] feat(core): Add JDBC backend operations for fileset (#2389)

xloya9e18f92b7914
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java
index 14f932fadd..6457c67e60 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/JDBCBackend.java
@@ -17,9 +17,11 @@ import com.datastrato.gravitino.exceptions.AlreadyExistsException;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.TableEntity;
import com.datastrato.gravitino.storage.relational.service.CatalogMetaService;
+import com.datastrato.gravitino.storage.relational.service.FilesetMetaService;
import com.datastrato.gravitino.storage.relational.service.MetalakeMetaService;
import com.datastrato.gravitino.storage.relational.service.SchemaMetaService;
import com.datastrato.gravitino.storage.relational.service.TableMetaService;
@@ -54,6 +56,8 @@ public class JDBCBackend implements RelationalBackend {
return (List<E>) SchemaMetaService.getInstance().listSchemasByNamespace(namespace);
case TABLE:
return (List<E>) TableMetaService.getInstance().listTablesByNamespace(namespace);
+ case FILESET:
+ return (List<E>) FilesetMetaService.getInstance().listFilesetsByNamespace(namespace);
default:
throw new UnsupportedEntityTypeException(
"Unsupported entity type: %s for list operation", entityType);
@@ -81,6 +85,8 @@ public class JDBCBackend implements RelationalBackend {
SchemaMetaService.getInstance().insertSchema((SchemaEntity) e, overwritten);
} else if (e instanceof TableEntity) {
TableMetaService.getInstance().insertTable((TableEntity) e, overwritten);
+ } else if (e instanceof FilesetEntity) {
+ FilesetMetaService.getInstance().insertFileset((FilesetEntity) e, overwritten);
} else {
throw new UnsupportedEntityTypeException(
"Unsupported entity type: %s for insert operation", e.getClass());
@@ -100,6 +106,8 @@ public class JDBCBackend implements RelationalBackend {
return (E) SchemaMetaService.getInstance().updateSchema(ident, updater);
case TABLE:
return (E) TableMetaService.getInstance().updateTable(ident, updater);
+ case FILESET:
+ return (E) FilesetMetaService.getInstance().updateFileset(ident, updater);
default:
throw new UnsupportedEntityTypeException(
"Unsupported entity type: %s for update operation", entityType);
@@ -118,6 +126,8 @@ public class JDBCBackend implements RelationalBackend {
return (E) SchemaMetaService.getInstance().getSchemaByIdentifier(ident);
case TABLE:
return (E) TableMetaService.getInstance().getTableByIdentifier(ident);
+ case FILESET:
+ return (E) FilesetMetaService.getInstance().getFilesetByIdentifier(ident);
default:
throw new UnsupportedEntityTypeException(
"Unsupported entity type: %s for get operation", entityType);
@@ -135,6 +145,8 @@ public class JDBCBackend implements RelationalBackend {
return SchemaMetaService.getInstance().deleteSchema(ident, cascade);
case TABLE:
return TableMetaService.getInstance().deleteTable(ident);
+ case FILESET:
+ return FilesetMetaService.getInstance().deleteFileset(ident);
default:
throw new UnsupportedEntityTypeException(
"Unsupported entity type: %s for delete operation", entityType);
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java
new file mode 100644
index 0000000000..33906f8b30
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetMetaMapper.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.storage.relational.mapper;
+
+import com.datastrato.gravitino.storage.relational.po.FilesetPO;
+import java.util.List;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Result;
+import org.apache.ibatis.annotations.Results;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+/**
+ * A MyBatis Mapper for fileset meta operation SQLs.
+ *
+ * <p>This interface class is a specification defined by MyBatis. It requires this interface class
+ * to identify the corresponding SQLs for execution. We can write SQLs in an additional XML file, or
+ * write SQLs with annotations in this interface Mapper. See: <a
+ * href="https://mybatis.org/mybatis-3/getting-started.html"></a>
+ */
+public interface FilesetMetaMapper {
+ String META_TABLE_NAME = "fileset_meta";
+
+ String VERSION_TABLE_NAME = "fileset_version_info";
+
+ @Select(
+ "SELECT fm.fileset_id, fm.fileset_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"
+ + " fm.type, fm.audit_info, fm.current_version, fm.last_version, fm.deleted_at,"
+ + " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"
+ + " vi.schema_id as version_schema_id, vi.fileset_id as version_fileset_id,"
+ + " vi.version, vi.fileset_comment, vi.properties, vi.storage_location,"
+ + " vi.deleted_at as version_deleted_at"
+ + " FROM "
+ + META_TABLE_NAME
+ + " fm INNER JOIN "
+ + VERSION_TABLE_NAME
+ + " vi ON fm.fileset_id = vi.fileset_id AND fm.current_version = vi.version"
+ + " WHERE fm.schema_id = #{schemaId} AND fm.deleted_at = 0 AND vi.deleted_at = 0")
+ @Results({
+ @Result(property = "filesetId", column = "fileset_id"),
+ @Result(property = "filesetName", column = "fileset_name"),
+ @Result(property = "metalakeId", column = "metalake_id"),
+ @Result(property = "catalogId", column = "catalog_id"),
+ @Result(property = "schemaId", column = "schema_id"),
+ @Result(property = "type", column = "type"),
+ @Result(property = "auditInfo", column = "audit_info"),
+ @Result(property = "currentVersion", column = "current_version"),
+ @Result(property = "lastVersion", column = "last_version"),
+ @Result(property = "deletedAt", column = "deleted_at"),
+ @Result(property = "filesetVersionPO.id", column = "id"),
+ @Result(property = "filesetVersionPO.metalakeId", column = "version_metalake_id"),
+ @Result(property = "filesetVersionPO.catalogId", column = "version_catalog_id"),
+ @Result(property = "filesetVersionPO.schemaId", column = "version_schema_id"),
+ @Result(property = "filesetVersionPO.filesetId", column = "version_fileset_id"),
+ @Result(property = "filesetVersionPO.version", column = "version"),
+ @Result(property = "filesetVersionPO.filesetComment", column = "fileset_comment"),
+ @Result(property = "filesetVersionPO.properties", column = "properties"),
+ @Result(property = "filesetVersionPO.storageLocation", column = "storage_location"),
+ @Result(property = "filesetVersionPO.deletedAt", column = "version_deleted_at")
+ })
+ List<FilesetPO> listFilesetPOsBySchemaId(@Param("schemaId") Long schemaId);
+
+ @Select(
+ "SELECT fileset_id as filesetId FROM "
+ + META_TABLE_NAME
+ + " WHERE schema_id = #{schemaId} AND fileset_name = #{filesetName}"
+ + " AND deleted_at = 0")
+ Long selectFilesetIdBySchemaIdAndName(
+ @Param("schemaId") Long schemaId, @Param("filesetName") String name);
+
+ @Select(
+ "SELECT fm.fileset_id, fm.fileset_name, fm.metalake_id, fm.catalog_id, fm.schema_id,"
+ + " fm.type, fm.audit_info, fm.current_version, fm.last_version, fm.deleted_at,"
+ + " vi.id, vi.metalake_id as version_metalake_id, vi.catalog_id as version_catalog_id,"
+ + " vi.schema_id as version_schema_id, vi.fileset_id as version_fileset_id,"
+ + " vi.version, vi.fileset_comment, vi.properties, vi.storage_location,"
+ + " vi.deleted_at as version_deleted_at"
+ + " FROM "
+ + META_TABLE_NAME
+ + " fm INNER JOIN "
+ + VERSION_TABLE_NAME
+ + " vi ON fm.fileset_id = vi.fileset_id AND fm.current_version = vi.version"
+ + " WHERE fm.schema_id = #{schemaId} AND fm.fileset_name = #{filesetName}"
+ + " AND fm.deleted_at = 0 AND vi.deleted_at = 0")
+ @Results({
+ @Result(property = "filesetId", column = "fileset_id"),
+ @Result(property = "filesetName", column = "fileset_name"),
+ @Result(property = "metalakeId", column = "metalake_id"),
+ @Result(property = "catalogId", column = "catalog_id"),
+ @Result(property = "schemaId", column = "schema_id"),
+ @Result(property = "type", column = "type"),
+ @Result(property = "auditInfo", column = "audit_info"),
+ @Result(property = "currentVersion", column = "current_version"),
+ @Result(property = "lastVersion", column = "last_version"),
+ @Result(property = "deletedAt", column = "deleted_at"),
+ @Result(property = "filesetVersionPO.id", column = "id"),
+ @Result(property = "filesetVersionPO.metalakeId", column = "version_metalake_id"),
+ @Result(property = "filesetVersionPO.catalogId", column = "version_catalog_id"),
+ @Result(property = "filesetVersionPO.schemaId", column = "version_schema_id"),
+ @Result(property = "filesetVersionPO.filesetId", column = "version_fileset_id"),
+ @Result(property = "filesetVersionPO.version", column = "version"),
+ @Result(property = "filesetVersionPO.filesetComment", column = "fileset_comment"),
+ @Result(property = "filesetVersionPO.properties", column = "properties"),
+ @Result(property = "filesetVersionPO.storageLocation", column = "storage_location"),
+ @Result(property = "filesetVersionPO.deletedAt", column = "version_deleted_at")
+ })
+ FilesetPO selectFilesetMetaBySchemaIdAndName(
+ @Param("schemaId") Long schemaId, @Param("filesetName") String name);
+
+ @Insert(
+ "INSERT INTO "
+ + META_TABLE_NAME
+ + "(fileset_id, fileset_name, metalake_id,"
+ + " catalog_id, schema_id, type, audit_info,"
+ + " current_version, last_version, deleted_at)"
+ + " VALUES("
+ + " #{filesetMeta.filesetId},"
+ + " #{filesetMeta.filesetName},"
+ + " #{filesetMeta.metalakeId},"
+ + " #{filesetMeta.catalogId},"
+ + " #{filesetMeta.schemaId},"
+ + " #{filesetMeta.type},"
+ + " #{filesetMeta.auditInfo},"
+ + " #{filesetMeta.currentVersion},"
+ + " #{filesetMeta.lastVersion},"
+ + " #{filesetMeta.deletedAt}"
+ + " )")
+ void insertFilesetMeta(@Param("filesetMeta") FilesetPO filesetPO);
+
+ @Insert(
+ "INSERT INTO "
+ + META_TABLE_NAME
+ + "(fileset_id, fileset_name, metalake_id,"
+ + " catalog_id, schema_id, type, audit_info,"
+ + " current_version, last_version, deleted_at)"
+ + " VALUES("
+ + " #{filesetMeta.filesetId},"
+ + " #{filesetMeta.filesetName},"
+ + " #{filesetMeta.metalakeId},"
+ + " #{filesetMeta.catalogId},"
+ + " #{filesetMeta.schemaId},"
+ + " #{filesetMeta.type},"
+ + " #{filesetMeta.auditInfo},"
+ + " #{filesetMeta.currentVersion},"
+ + " #{filesetMeta.lastVersion},"
+ + " #{filesetMeta.deletedAt}"
+ + " )"
+ + " ON DUPLICATE KEY UPDATE"
+ + " fileset_name = #{filesetMeta.filesetName},"
+ + " metalake_id = #{filesetMeta.metalakeId},"
+ + " catalog_id = #{filesetMeta.catalogId},"
+ + " schema_id = #{filesetMeta.schemaId},"
+ + " type = #{filesetMeta.type},"
+ + " audit_info = #{filesetMeta.auditInfo},"
+ + " current_version = #{filesetMeta.currentVersion},"
+ + " last_version = #{filesetMeta.lastVersion},"
+ + " deleted_at = #{filesetMeta.deletedAt}")
+ void insertFilesetMetaOnDuplicateKeyUpdate(@Param("filesetMeta") FilesetPO filesetPO);
+
+ @Update(
+ "UPDATE "
+ + META_TABLE_NAME
+ + " SET fileset_name = #{newFilesetMeta.filesetName},"
+ + " metalake_id = #{newFilesetMeta.metalakeId},"
+ + " catalog_id = #{newFilesetMeta.catalogId},"
+ + " schema_id = #{newFilesetMeta.schemaId},"
+ + " type = #{newFilesetMeta.type},"
+ + " audit_info = #{newFilesetMeta.auditInfo},"
+ + " current_version = #{newFilesetMeta.currentVersion},"
+ + " last_version = #{newFilesetMeta.lastVersion},"
+ + " deleted_at = #{newFilesetMeta.deletedAt}"
+ + " WHERE fileset_id = #{oldFilesetMeta.filesetId}"
+ + " AND fileset_name = #{oldFilesetMeta.filesetName}"
+ + " AND metalake_id = #{oldFilesetMeta.metalakeId}"
+ + " AND catalog_id = #{oldFilesetMeta.catalogId}"
+ + " AND schema_id = #{oldFilesetMeta.schemaId}"
+ + " AND type = #{oldFilesetMeta.type}"
+ + " AND audit_info = #{oldFilesetMeta.auditInfo}"
+ + " AND current_version = #{oldFilesetMeta.currentVersion}"
+ + " AND last_version = #{oldFilesetMeta.lastVersion}"
+ + " AND deleted_at = 0")
+ Integer updateFilesetMeta(
+ @Param("newFilesetMeta") FilesetPO newFilesetPO,
+ @Param("oldFilesetMeta") FilesetPO oldFilesetPO);
+
+ @Update(
+ "UPDATE "
+ + META_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0")
+ Integer softDeleteFilesetMetasByMetalakeId(@Param("metalakeId") Long metalakeId);
+
+ @Update(
+ "UPDATE "
+ + META_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE catalog_id = #{catalogId} AND deleted_at = 0")
+ Integer softDeleteFilesetMetasByCatalogId(@Param("catalogId") Long catalogId);
+
+ @Update(
+ "UPDATE "
+ + META_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE schema_id = #{schemaId} AND deleted_at = 0")
+ Integer softDeleteFilesetMetasBySchemaId(@Param("schemaId") Long schemaId);
+
+ @Update(
+ "UPDATE "
+ + META_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE fileset_id = #{filesetId} AND deleted_at = 0")
+ Integer softDeleteFilesetMetasByFilesetId(@Param("filesetId") Long filesetId);
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java
new file mode 100644
index 0000000000..b2df6ab43c
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/mapper/FilesetVersionMapper.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.storage.relational.mapper;
+
+import com.datastrato.gravitino.storage.relational.po.FilesetVersionPO;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+/**
+ * A MyBatis Mapper for fileset version info operation SQLs.
+ *
+ * <p>This interface class is a specification defined by MyBatis. It requires this interface class
+ * to identify the corresponding SQLs for execution. We can write SQLs in an additional XML file, or
+ * write SQLs with annotations in this interface Mapper. See: <a
+ * href="https://mybatis.org/mybatis-3/getting-started.html"></a>
+ */
+public interface FilesetVersionMapper {
+ String VERSION_TABLE_NAME = "fileset_version_info";
+
+ @Insert(
+ "INSERT INTO "
+ + VERSION_TABLE_NAME
+ + "(metalake_id, catalog_id, schema_id, fileset_id,"
+ + " version, fileset_comment, properties, storage_location,"
+ + " deleted_at)"
+ + " VALUES("
+ + " #{filesetVersion.metalakeId},"
+ + " #{filesetVersion.catalogId},"
+ + " #{filesetVersion.schemaId},"
+ + " #{filesetVersion.filesetId},"
+ + " #{filesetVersion.version},"
+ + " #{filesetVersion.filesetComment},"
+ + " #{filesetVersion.properties},"
+ + " #{filesetVersion.storageLocation},"
+ + " #{filesetVersion.deletedAt}"
+ + " )")
+ void insertFilesetVersion(@Param("filesetVersion") FilesetVersionPO filesetVersionPO);
+
+ @Insert(
+ "INSERT INTO "
+ + VERSION_TABLE_NAME
+ + "(metalake_id, catalog_id, schema_id, fileset_id,"
+ + " version, fileset_comment, properties, storage_location,"
+ + " deleted_at)"
+ + " VALUES("
+ + " #{filesetVersion.metalakeId},"
+ + " #{filesetVersion.catalogId},"
+ + " #{filesetVersion.schemaId},"
+ + " #{filesetVersion.filesetId},"
+ + " #{filesetVersion.version},"
+ + " #{filesetVersion.filesetComment},"
+ + " #{filesetVersion.properties},"
+ + " #{filesetVersion.storageLocation},"
+ + " #{filesetVersion.deletedAt}"
+ + " )"
+ + " ON DUPLICATE KEY UPDATE"
+ + " metalake_id = #{filesetVersion.metalakeId},"
+ + " catalog_id = #{filesetVersion.catalogId},"
+ + " schema_id = #{filesetVersion.schemaId},"
+ + " fileset_id = #{filesetVersion.filesetId},"
+ + " version = #{filesetVersion.version},"
+ + " fileset_comment = #{filesetVersion.filesetComment},"
+ + " properties = #{filesetVersion.properties},"
+ + " storage_location = #{filesetVersion.storageLocation},"
+ + " deleted_at = #{filesetVersion.deletedAt}")
+ void insertFilesetVersionOnDuplicateKeyUpdate(
+ @Param("filesetVersion") FilesetVersionPO filesetVersionPO);
+
+ @Update(
+ "UPDATE "
+ + VERSION_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0")
+ Integer softDeleteFilesetVersionsByMetalakeId(@Param("metalakeId") Long metalakeId);
+
+ @Update(
+ "UPDATE "
+ + VERSION_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE catalog_id = #{catalogId} AND deleted_at = 0")
+ Integer softDeleteFilesetVersionsByCatalogId(@Param("catalogId") Long catalogId);
+
+ @Update(
+ "UPDATE "
+ + VERSION_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE schema_id = #{schemaId} AND deleted_at = 0")
+ Integer softDeleteFilesetVersionsBySchemaId(@Param("schemaId") Long schemaId);
+
+ @Update(
+ "UPDATE "
+ + VERSION_TABLE_NAME
+ + " SET deleted_at = UNIX_TIMESTAMP()"
+ + " WHERE fileset_id = #{filesetId} AND deleted_at = 0")
+ Integer softDeleteFilesetVersionsByFilesetId(@Param("filesetId") Long filesetId);
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetPO.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetPO.java
new file mode 100644
index 0000000000..833617ffec
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetPO.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.storage.relational.po;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class FilesetPO {
+ private Long filesetId;
+ private String filesetName;
+ private Long metalakeId;
+ private Long catalogId;
+ private Long schemaId;
+ private String type;
+ private String auditInfo;
+ private Long currentVersion;
+ private Long lastVersion;
+ private Long deletedAt;
+ private FilesetVersionPO filesetVersionPO;
+
+ public Long getFilesetId() {
+ return filesetId;
+ }
+
+ public String getFilesetName() {
+ return filesetName;
+ }
+
+ public Long getMetalakeId() {
+ return metalakeId;
+ }
+
+ public Long getCatalogId() {
+ return catalogId;
+ }
+
+ public Long getSchemaId() {
+ return schemaId;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getAuditInfo() {
+ return auditInfo;
+ }
+
+ public Long getCurrentVersion() {
+ return currentVersion;
+ }
+
+ public Long getLastVersion() {
+ return lastVersion;
+ }
+
+ public Long getDeletedAt() {
+ return deletedAt;
+ }
+
+ public FilesetVersionPO getFilesetVersionPO() {
+ return filesetVersionPO;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof FilesetPO)) {
+ return false;
+ }
+ FilesetPO filesetPO = (FilesetPO) o;
+ return Objects.equal(getFilesetId(), filesetPO.getFilesetId())
+ && Objects.equal(getFilesetName(), filesetPO.getFilesetName())
+ && Objects.equal(getMetalakeId(), filesetPO.getMetalakeId())
+ && Objects.equal(getCatalogId(), filesetPO.getCatalogId())
+ && Objects.equal(getSchemaId(), filesetPO.getSchemaId())
+ && Objects.equal(getType(), filesetPO.getType())
+ && Objects.equal(getAuditInfo(), filesetPO.getAuditInfo())
+ && Objects.equal(getCurrentVersion(), filesetPO.getCurrentVersion())
+ && Objects.equal(getLastVersion(), filesetPO.getLastVersion())
+ && Objects.equal(getDeletedAt(), filesetPO.getDeletedAt())
+ && Objects.equal(getFilesetVersionPO(), filesetPO.getFilesetVersionPO());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(
+ getFilesetId(),
+ getFilesetName(),
+ getMetalakeId(),
+ getCatalogId(),
+ getSchemaId(),
+ getType(),
+ getAuditInfo(),
+ getCurrentVersion(),
+ getLastVersion(),
+ getDeletedAt(),
+ getFilesetVersionPO());
+ }
+
+ public static class Builder {
+ private final FilesetPO filesetPO;
+
+ public Builder() {
+ filesetPO = new FilesetPO();
+ }
+
+ public FilesetPO.Builder withFilesetId(Long filesetId) {
+ filesetPO.filesetId = filesetId;
+ return this;
+ }
+
+ public FilesetPO.Builder withFilesetName(String filesetName) {
+ filesetPO.filesetName = filesetName;
+ return this;
+ }
+
+ public FilesetPO.Builder withMetalakeId(Long metalakeId) {
+ filesetPO.metalakeId = metalakeId;
+ return this;
+ }
+
+ public FilesetPO.Builder withCatalogId(Long catalogId) {
+ filesetPO.catalogId = catalogId;
+ return this;
+ }
+
+ public FilesetPO.Builder withSchemaId(Long schemaId) {
+ filesetPO.schemaId = schemaId;
+ return this;
+ }
+
+ public FilesetPO.Builder withType(String type) {
+ filesetPO.type = type;
+ return this;
+ }
+
+ public FilesetPO.Builder withAuditInfo(String auditInfo) {
+ filesetPO.auditInfo = auditInfo;
+ return this;
+ }
+
+ public FilesetPO.Builder withCurrentVersion(Long currentVersion) {
+ filesetPO.currentVersion = currentVersion;
+ return this;
+ }
+
+ public FilesetPO.Builder withLastVersion(Long lastVersion) {
+ filesetPO.lastVersion = lastVersion;
+ return this;
+ }
+
+ public FilesetPO.Builder withDeletedAt(Long deletedAt) {
+ filesetPO.deletedAt = deletedAt;
+ return this;
+ }
+
+ public FilesetPO.Builder withFilesetVersionPO(FilesetVersionPO filesetVersionPO) {
+ filesetPO.filesetVersionPO = filesetVersionPO;
+ return this;
+ }
+
+ public Long getFilesetMetalakeId() {
+ Preconditions.checkState(filesetPO.getMetalakeId() != null, "Metalake id is null");
+ return filesetPO.getMetalakeId();
+ }
+
+ public Long getFilesetCatalogId() {
+ Preconditions.checkState(filesetPO.getCatalogId() != null, "Catalog id is null");
+ return filesetPO.getCatalogId();
+ }
+
+ public Long getFilesetSchemaId() {
+ Preconditions.checkState(filesetPO.getSchemaId() != null, "Schema id is null");
+ return filesetPO.getSchemaId();
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(filesetPO.filesetId != null, "Fileset id is required");
+ Preconditions.checkArgument(filesetPO.filesetName != null, "Fileset name is required");
+ Preconditions.checkArgument(filesetPO.metalakeId != null, "Metalake id is required");
+ Preconditions.checkArgument(filesetPO.catalogId != null, "Catalog id is required");
+ Preconditions.checkArgument(filesetPO.schemaId != null, "Schema id is required");
+ Preconditions.checkArgument(filesetPO.auditInfo != null, "Audit info is required");
+ Preconditions.checkArgument(filesetPO.currentVersion != null, "Current version is required");
+ Preconditions.checkArgument(filesetPO.lastVersion != null, "Last version is required");
+ Preconditions.checkArgument(filesetPO.deletedAt != null, "Deleted at is required");
+ Preconditions.checkArgument(
+ filesetPO.filesetVersionPO != null, "Fileset version is required");
+ }
+
+ public FilesetPO build() {
+ validate();
+ return filesetPO;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetVersionPO.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetVersionPO.java
new file mode 100644
index 0000000000..98dd628b58
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/po/FilesetVersionPO.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.storage.relational.po;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+
+public class FilesetVersionPO {
+ private Long id;
+ private Long metalakeId;
+ private Long catalogId;
+ private Long schemaId;
+ private Long filesetId;
+ private Long version;
+ private String filesetComment;
+ private String properties;
+ private String storageLocation;
+ private Long deletedAt;
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getMetalakeId() {
+ return metalakeId;
+ }
+
+ public Long getCatalogId() {
+ return catalogId;
+ }
+
+ public Long getSchemaId() {
+ return schemaId;
+ }
+
+ public Long getFilesetId() {
+ return filesetId;
+ }
+
+ public Long getVersion() {
+ return version;
+ }
+
+ public String getFilesetComment() {
+ return filesetComment;
+ }
+
+ public String getProperties() {
+ return properties;
+ }
+
+ public String getStorageLocation() {
+ return storageLocation;
+ }
+
+ public Long getDeletedAt() {
+ return deletedAt;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof FilesetVersionPO)) {
+ return false;
+ }
+ FilesetVersionPO that = (FilesetVersionPO) o;
+ return Objects.equal(getId(), that.getId())
+ && Objects.equal(getMetalakeId(), that.getMetalakeId())
+ && Objects.equal(getCatalogId(), that.getCatalogId())
+ && Objects.equal(getSchemaId(), that.getSchemaId())
+ && Objects.equal(getFilesetId(), that.getFilesetId())
+ && Objects.equal(getVersion(), that.getVersion())
+ && Objects.equal(getFilesetComment(), that.getFilesetComment())
+ && Objects.equal(getProperties(), that.getProperties())
+ && Objects.equal(getStorageLocation(), that.getStorageLocation())
+ && Objects.equal(getDeletedAt(), that.getDeletedAt());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(
+ getId(),
+ getMetalakeId(),
+ getCatalogId(),
+ getSchemaId(),
+ getFilesetId(),
+ getVersion(),
+ getFilesetComment(),
+ getProperties(),
+ getStorageLocation(),
+ getDeletedAt());
+ }
+
+ public static class Builder {
+ private final FilesetVersionPO filesetVersionPO;
+
+ public Builder() {
+ filesetVersionPO = new FilesetVersionPO();
+ }
+
+ public Builder withId(Long id) {
+ filesetVersionPO.id = id;
+ return this;
+ }
+
+ public Builder withMetalakeId(Long metalakeId) {
+ filesetVersionPO.metalakeId = metalakeId;
+ return this;
+ }
+
+ public Builder withCatalogId(Long catalogId) {
+ filesetVersionPO.catalogId = catalogId;
+ return this;
+ }
+
+ public Builder withSchemaId(Long schemaId) {
+ filesetVersionPO.schemaId = schemaId;
+ return this;
+ }
+
+ public Builder withFilesetId(Long filesetId) {
+ filesetVersionPO.filesetId = filesetId;
+ return this;
+ }
+
+ public Builder withVersion(Long version) {
+ filesetVersionPO.version = version;
+ return this;
+ }
+
+ public Builder withFilesetComment(String filesetComment) {
+ filesetVersionPO.filesetComment = filesetComment;
+ return this;
+ }
+
+ public Builder withProperties(String properties) {
+ filesetVersionPO.properties = properties;
+ return this;
+ }
+
+ public Builder withStorageLocation(String storageLocation) {
+ filesetVersionPO.storageLocation = storageLocation;
+ return this;
+ }
+
+ public Builder withDeletedAt(Long deletedAt) {
+ filesetVersionPO.deletedAt = deletedAt;
+ return this;
+ }
+
+ private void validate() {
+ Preconditions.checkArgument(filesetVersionPO.metalakeId != null, "Metalake id is required");
+ Preconditions.checkArgument(filesetVersionPO.catalogId != null, "Catalog id is required");
+ Preconditions.checkArgument(filesetVersionPO.schemaId != null, "Schema id is required");
+ Preconditions.checkArgument(filesetVersionPO.filesetId != null, "Fileset id is required");
+ Preconditions.checkArgument(filesetVersionPO.version != null, "Fileset version is required");
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(filesetVersionPO.storageLocation), "Storage location is required");
+ Preconditions.checkArgument(filesetVersionPO.deletedAt != null, "Deleted at is required");
+ }
+
+ public FilesetVersionPO build() {
+ validate();
+ return filesetVersionPO;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java
index a6256e9d16..06f25ec84c 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CatalogMetaService.java
@@ -13,6 +13,8 @@ import com.datastrato.gravitino.exceptions.NonEmptyEntityException;
import com.datastrato.gravitino.meta.CatalogEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.storage.relational.mapper.CatalogMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetVersionMapper;
import com.datastrato.gravitino.storage.relational.mapper.SchemaMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.TableMetaMapper;
import com.datastrato.gravitino.storage.relational.po.CatalogPO;
@@ -179,9 +181,14 @@ public class CatalogMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasByCatalogId(catalogId)),
- () -> {
- // TODO We will cascade delete the metadata of sub-resources under the catalog
- });
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.softDeleteFilesetMetasByCatalogId(catalogId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> mapper.softDeleteFilesetVersionsByCatalogId(catalogId)));
} else {
List<SchemaEntity> schemaEntities =
SchemaMetaService.getInstance()
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CommonMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CommonMetaService.java
index 20bc92fb25..c270dda7c6 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CommonMetaService.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/CommonMetaService.java
@@ -21,7 +21,7 @@ public class CommonMetaService {
public Long getParentEntityIdByNamespace(Namespace namespace) {
Preconditions.checkArgument(
!namespace.isEmpty() && namespace.levels().length <= 3,
- "Namespace should not be empty and length should be less and equal than 3");
+ "Namespace should not be empty and length should be less than or equal to 3.");
Long parentEntityId = null;
for (int level = 0; level < namespace.levels().length; level++) {
String name = namespace.level(level);
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java
new file mode 100644
index 0000000000..be5d26a6b0
--- /dev/null
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/FilesetMetaService.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2024 Datastrato Pvt Ltd.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.storage.relational.service;
+
+import com.datastrato.gravitino.Entity;
+import com.datastrato.gravitino.HasIdentifier;
+import com.datastrato.gravitino.NameIdentifier;
+import com.datastrato.gravitino.Namespace;
+import com.datastrato.gravitino.exceptions.NoSuchEntityException;
+import com.datastrato.gravitino.meta.FilesetEntity;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetVersionMapper;
+import com.datastrato.gravitino.storage.relational.po.FilesetPO;
+import com.datastrato.gravitino.storage.relational.utils.ExceptionUtils;
+import com.datastrato.gravitino.storage.relational.utils.POConverters;
+import com.datastrato.gravitino.storage.relational.utils.SessionUtils;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * The service class for fileset metadata and version info. It provides the basic database
+ * operations for fileset and version info.
+ */
+public class FilesetMetaService {
+ private static final FilesetMetaService INSTANCE = new FilesetMetaService();
+
+ public static FilesetMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private FilesetMetaService() {}
+
+ public FilesetPO getFilesetPOBySchemaIdAndName(Long schemaId, String filesetName) {
+ FilesetPO filesetPO =
+ SessionUtils.getWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.selectFilesetMetaBySchemaIdAndName(schemaId, filesetName));
+
+ if (filesetPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.FILESET.name().toLowerCase(),
+ filesetName);
+ }
+ return filesetPO;
+ }
+
+ public Long getFilesetIdBySchemaIdAndName(Long schemaId, String filesetName) {
+ Long filesetId =
+ SessionUtils.getWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.selectFilesetIdBySchemaIdAndName(schemaId, filesetName));
+
+ if (filesetId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.FILESET.name().toLowerCase(),
+ filesetName);
+ }
+ return filesetId;
+ }
+
+ public FilesetEntity getFilesetByIdentifier(NameIdentifier identifier) {
+ NameIdentifier.checkFileset(identifier);
+
+ String filesetName = identifier.name();
+
+ Long schemaId =
+ CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());
+
+ FilesetPO filesetPO = getFilesetPOBySchemaIdAndName(schemaId, filesetName);
+
+ return POConverters.fromFilesetPO(filesetPO, identifier.namespace());
+ }
+
+ public List<FilesetEntity> listFilesetsByNamespace(Namespace namespace) {
+ Namespace.checkFileset(namespace);
+
+ Long schemaId = CommonMetaService.getInstance().getParentEntityIdByNamespace(namespace);
+
+ List<FilesetPO> filesetPOs =
+ SessionUtils.getWithoutCommit(
+ FilesetMetaMapper.class, mapper -> mapper.listFilesetPOsBySchemaId(schemaId));
+
+ return POConverters.fromFilesetPOs(filesetPOs, namespace);
+ }
+
+ public void insertFileset(FilesetEntity filesetEntity, boolean overwrite) {
+ try {
+ NameIdentifier.checkFileset(filesetEntity.nameIdentifier());
+
+ FilesetPO.Builder builder = new FilesetPO.Builder();
+ fillFilesetPOBuilderParentEntityId(builder, filesetEntity.namespace());
+
+ FilesetPO po = POConverters.initializeFilesetPOWithVersion(filesetEntity, builder);
+
+ // insert both fileset meta table and version table
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertFilesetMetaOnDuplicateKeyUpdate(po);
+ } else {
+ mapper.insertFilesetMeta(po);
+ }
+ }),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertFilesetVersionOnDuplicateKeyUpdate(po.getFilesetVersionPO());
+ } else {
+ mapper.insertFilesetVersion(po.getFilesetVersionPO());
+ }
+ }));
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLConstraintException(
+ re, Entity.EntityType.FILESET, filesetEntity.nameIdentifier().toString());
+ throw re;
+ }
+ }
+
+ public <E extends Entity & HasIdentifier> FilesetEntity updateFileset(
+ NameIdentifier identifier, Function<E, E> updater) throws IOException {
+ NameIdentifier.checkFileset(identifier);
+
+ String filesetName = identifier.name();
+
+ Long schemaId =
+ CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());
+
+ FilesetPO oldFilesetPO = getFilesetPOBySchemaIdAndName(schemaId, filesetName);
+ FilesetEntity oldFilesetEntity =
+ POConverters.fromFilesetPO(oldFilesetPO, identifier.namespace());
+ FilesetEntity newEntity = (FilesetEntity) updater.apply((E) oldFilesetEntity);
+ Preconditions.checkArgument(
+ Objects.equals(oldFilesetEntity.id(), newEntity.id()),
+ "The updated fileset entity id: %s should be same with the table entity id before: %s",
+ newEntity.id(),
+ oldFilesetEntity.id());
+
+ Integer updateResult;
+ try {
+ boolean checkNeedUpdateVersion =
+ POConverters.checkFilesetVersionNeedUpdate(oldFilesetPO.getFilesetVersionPO(), newEntity);
+ FilesetPO newFilesetPO =
+ POConverters.updateFilesetPOWithVersion(oldFilesetPO, newEntity, checkNeedUpdateVersion);
+ if (checkNeedUpdateVersion) {
+ // These operations are guaranteed to be atomic by the transaction. If version info is
+ // inserted successfully and the uniqueness is guaranteed by `fileset_id + version +
+ // deleted_at`, it means that no other transaction has been inserted (if a uniqueness
+ // conflict occurs, the transaction will be rolled back), then we can consider that the
+ // fileset meta update is successful
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> mapper.insertFilesetVersion(newFilesetPO.getFilesetVersionPO())),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.updateFilesetMeta(newFilesetPO, oldFilesetPO)));
+ // we set the updateResult to 1 to indicate that the update is successful
+ updateResult = 1;
+ } else {
+ updateResult =
+ SessionUtils.doWithCommitAndFetchResult(
+ FilesetMetaMapper.class,
+ mapper -> mapper.updateFilesetMeta(newFilesetPO, oldFilesetPO));
+ }
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLConstraintException(
+ re, Entity.EntityType.FILESET, newEntity.nameIdentifier().toString());
+ throw re;
+ }
+
+ if (updateResult > 0) {
+ return newEntity;
+ } else {
+ throw new IOException("Failed to update the entity: " + identifier);
+ }
+ }
+
+ public boolean deleteFileset(NameIdentifier identifier) {
+ NameIdentifier.checkFileset(identifier);
+
+ String filesetName = identifier.name();
+
+ Long schemaId =
+ CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());
+
+ Long filesetId = getFilesetIdBySchemaIdAndName(schemaId, filesetName);
+
+ // We should delete meta and version info
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.softDeleteFilesetMetasByFilesetId(filesetId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> mapper.softDeleteFilesetVersionsByFilesetId(filesetId)));
+
+ return true;
+ }
+
+ private void fillFilesetPOBuilderParentEntityId(FilesetPO.Builder builder, Namespace namespace) {
+ Namespace.checkFileset(namespace);
+ Long parentEntityId = null;
+ for (int level = 0; level < namespace.levels().length; level++) {
+ String name = namespace.level(level);
+ switch (level) {
+ case 0:
+ parentEntityId = MetalakeMetaService.getInstance().getMetalakeIdByName(name);
+ builder.withMetalakeId(parentEntityId);
+ continue;
+ case 1:
+ parentEntityId =
+ CatalogMetaService.getInstance()
+ .getCatalogIdByMetalakeIdAndName(parentEntityId, name);
+ builder.withCatalogId(parentEntityId);
+ continue;
+ case 2:
+ parentEntityId =
+ SchemaMetaService.getInstance().getSchemaIdByCatalogIdAndName(parentEntityId, name);
+ builder.withSchemaId(parentEntityId);
+ break;
+ }
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java
index 120c364bae..285a87b83c 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/MetalakeMetaService.java
@@ -14,6 +14,8 @@ import com.datastrato.gravitino.exceptions.NonEmptyEntityException;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
import com.datastrato.gravitino.storage.relational.mapper.CatalogMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetVersionMapper;
import com.datastrato.gravitino.storage.relational.mapper.MetalakeMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.SchemaMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.TableMetaMapper;
@@ -156,9 +158,14 @@ public class MetalakeMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasByMetalakeId(metalakeId)),
- () -> {
- // TODO We will cascade delete the metadata of sub-resources under the metalake
- });
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.softDeleteFilesetMetasByMetalakeId(metalakeId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> mapper.softDeleteFilesetVersionsByMetalakeId(metalakeId)));
} else {
List<CatalogEntity> catalogEntities =
CatalogMetaService.getInstance()
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java
index 374106a423..ce345e260a 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/service/SchemaMetaService.java
@@ -10,8 +10,11 @@ import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.exceptions.NonEmptyEntityException;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.TableEntity;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetVersionMapper;
import com.datastrato.gravitino.storage.relational.mapper.SchemaMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.TableMetaMapper;
import com.datastrato.gravitino.storage.relational.po.SchemaPO;
@@ -169,9 +172,14 @@ public class SchemaMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasBySchemaId(schemaId)),
- () -> {
- // TODO We will cascade delete the metadata of sub-resources under the schema
- });
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetMetaMapper.class,
+ mapper -> mapper.softDeleteFilesetMetasBySchemaId(schemaId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ FilesetVersionMapper.class,
+ mapper -> mapper.softDeleteFilesetVersionsBySchemaId(schemaId)));
} else {
List<TableEntity> tableEntities =
TableMetaService.getInstance()
@@ -184,6 +192,17 @@ public class SchemaMetaService {
throw new NonEmptyEntityException(
"Entity %s has sub-entities, you should remove sub-entities first", identifier);
}
+ List<FilesetEntity> filesetEntities =
+ FilesetMetaService.getInstance()
+ .listFilesetsByNamespace(
+ Namespace.ofFileset(
+ identifier.namespace().level(0),
+ identifier.namespace().level(1),
+ schemaName));
+ if (!filesetEntities.isEmpty()) {
+ throw new NonEmptyEntityException(
+ "Entity %s has sub-entities, you should remove sub-entities first", identifier);
+ }
SessionUtils.doWithCommit(
SchemaMetaMapper.class, mapper -> mapper.softDeleteSchemaMetasBySchemaId(schemaId));
}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/session/SqlSessionFactoryHelper.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
index a73daf42e3..2ba959853f 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
@@ -8,6 +8,8 @@ package com.datastrato.gravitino.storage.relational.session;
import com.datastrato.gravitino.Config;
import com.datastrato.gravitino.Configs;
import com.datastrato.gravitino.storage.relational.mapper.CatalogMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import com.datastrato.gravitino.storage.relational.mapper.FilesetVersionMapper;
import com.datastrato.gravitino.storage.relational.mapper.MetalakeMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.SchemaMetaMapper;
import com.datastrato.gravitino.storage.relational.mapper.TableMetaMapper;
@@ -80,6 +82,8 @@ public class SqlSessionFactoryHelper {
configuration.addMapper(CatalogMetaMapper.class);
configuration.addMapper(SchemaMetaMapper.class);
configuration.addMapper(TableMetaMapper.class);
+ configuration.addMapper(FilesetMetaMapper.class);
+ configuration.addMapper(FilesetVersionMapper.class);
// Create the SqlSessionFactory object, it is a singleton object
if (sqlSessionFactory == null) {
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java
index 271389e21b..21ac6057b6 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/ExceptionUtils.java
@@ -14,12 +14,11 @@ public class ExceptionUtils {
public static void checkSQLConstraintException(
RuntimeException re, Entity.EntityType type, String entityName) {
if (re.getCause() != null
- && re.getCause().getCause() != null
- && re.getCause().getCause() instanceof SQLIntegrityConstraintViolationException) {
+ && re.getCause() instanceof SQLIntegrityConstraintViolationException) {
// TODO We should make more fine-grained exception judgments
- // Usually throwing `SQLIntegrityConstraintViolationException` means that
- // SQL violates the constraints of `primary key` and `unique key`.
- // We simply think that the entity already exists at this time.
+ // Usually throwing `SQLIntegrityConstraintViolationException` means that
+ // SQL violates the constraints of `primary key` and `unique key`.
+ // We simply think that the entity already exists at this time.
throw new EntityAlreadyExistsException(
String.format("%s entity: %s already exists", type.name(), entityName));
}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/POConverters.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/POConverters.java
index baf489523a..9249906571 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/POConverters.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/POConverters.java
@@ -7,14 +7,18 @@ package com.datastrato.gravitino.storage.relational.utils;
import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.Namespace;
+import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.json.JsonUtils;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.SchemaVersion;
import com.datastrato.gravitino.meta.TableEntity;
import com.datastrato.gravitino.storage.relational.po.CatalogPO;
+import com.datastrato.gravitino.storage.relational.po.FilesetPO;
+import com.datastrato.gravitino.storage.relational.po.FilesetVersionPO;
import com.datastrato.gravitino.storage.relational.po.MetalakePO;
import com.datastrato.gravitino.storage.relational.po.SchemaPO;
import com.datastrato.gravitino.storage.relational.po.TablePO;
@@ -22,6 +26,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
/** POConverters is a utility class to convert PO to Base and vice versa. */
public class POConverters {
@@ -363,7 +368,7 @@ public class POConverters {
*
* @param tablePO TablePO object to be converted
* @param namespace Namespace object to be associated with the table
- * @return TableEntity object from SchemaPO object
+ * @return TableEntity object from TablePO object
*/
public static TableEntity fromTablePO(TablePO tablePO, Namespace namespace) {
try {
@@ -384,11 +389,158 @@ public class POConverters {
*
* @param tablePOs list of TablePO objects
* @param namespace Namespace object to be associated with the table
- * @return list of TableEntity objects from list of SchemaPO objects
+ * @return list of TableEntity objects from list of TablePO objects
*/
public static List<TableEntity> fromTablePOs(List<TablePO> tablePOs, Namespace namespace) {
return tablePOs.stream()
.map(tablePO -> POConverters.fromTablePO(tablePO, namespace))
.collect(Collectors.toList());
}
+
+ /**
+ * Initialize FilesetPO
+ *
+ * @param filesetEntity FilesetEntity object
+ * @return FilesetPO object with version initialized
+ */
+ public static FilesetPO initializeFilesetPOWithVersion(
+ FilesetEntity filesetEntity, FilesetPO.Builder builder) {
+ try {
+ FilesetVersionPO filesetVersionPO =
+ new FilesetVersionPO.Builder()
+ .withMetalakeId(builder.getFilesetMetalakeId())
+ .withCatalogId(builder.getFilesetCatalogId())
+ .withSchemaId(builder.getFilesetSchemaId())
+ .withFilesetId(filesetEntity.id())
+ .withVersion(INIT_VERSION)
+ .withFilesetComment(filesetEntity.comment())
+ .withStorageLocation(filesetEntity.storageLocation())
+ .withProperties(
+ JsonUtils.anyFieldMapper().writeValueAsString(filesetEntity.properties()))
+ .withDeletedAt(DEFAULT_DELETED_AT)
+ .build();
+ return builder
+ .withFilesetId(filesetEntity.id())
+ .withFilesetName(filesetEntity.name())
+ .withType(filesetEntity.filesetType().name())
+ .withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(filesetEntity.auditInfo()))
+ .withCurrentVersion(INIT_VERSION)
+ .withLastVersion(INIT_VERSION)
+ .withDeletedAt(DEFAULT_DELETED_AT)
+ .withFilesetVersionPO(filesetVersionPO)
+ .build();
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to serialize json object:", e);
+ }
+ }
+
+ /**
+ * Update FilesetPO version
+ *
+ * @param oldFilesetPO the old FilesetPO object
+ * @param newFileset the new FilesetEntity object
+ * @return FilesetPO object with updated version
+ */
+ public static FilesetPO updateFilesetPOWithVersion(
+ FilesetPO oldFilesetPO, FilesetEntity newFileset, boolean needUpdateVersion) {
+ try {
+ Long lastVersion = oldFilesetPO.getLastVersion();
+ Long currentVersion;
+ FilesetVersionPO newFilesetVersionPO;
+ // Will set the version to the last version + 1
+ if (needUpdateVersion) {
+ lastVersion++;
+ currentVersion = lastVersion;
+ newFilesetVersionPO =
+ new FilesetVersionPO.Builder()
+ .withMetalakeId(oldFilesetPO.getMetalakeId())
+ .withCatalogId(oldFilesetPO.getCatalogId())
+ .withSchemaId(oldFilesetPO.getSchemaId())
+ .withFilesetId(newFileset.id())
+ .withVersion(currentVersion)
+ .withFilesetComment(newFileset.comment())
+ .withStorageLocation(newFileset.storageLocation())
+ .withProperties(
+ JsonUtils.anyFieldMapper().writeValueAsString(newFileset.properties()))
+ .withDeletedAt(DEFAULT_DELETED_AT)
+ .build();
+ } else {
+ currentVersion = oldFilesetPO.getCurrentVersion();
+ newFilesetVersionPO = oldFilesetPO.getFilesetVersionPO();
+ }
+ return new FilesetPO.Builder()
+ .withFilesetId(newFileset.id())
+ .withFilesetName(newFileset.name())
+ .withMetalakeId(oldFilesetPO.getMetalakeId())
+ .withCatalogId(oldFilesetPO.getCatalogId())
+ .withSchemaId(oldFilesetPO.getSchemaId())
+ .withType(newFileset.filesetType().name())
+ .withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(newFileset.auditInfo()))
+ .withCurrentVersion(currentVersion)
+ .withLastVersion(lastVersion)
+ .withDeletedAt(DEFAULT_DELETED_AT)
+ .withFilesetVersionPO(newFilesetVersionPO)
+ .build();
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to serialize json object:", e);
+ }
+ }
+
+ public static boolean checkFilesetVersionNeedUpdate(
+ FilesetVersionPO oldFilesetVersionPO, FilesetEntity newFileset) {
+ if (!StringUtils.equals(oldFilesetVersionPO.getFilesetComment(), newFileset.comment())
+ || !StringUtils.equals(
+ oldFilesetVersionPO.getStorageLocation(), newFileset.storageLocation())) {
+ return true;
+ }
+
+ try {
+ Map<String, String> oldProperties =
+ JsonUtils.anyFieldMapper().readValue(oldFilesetVersionPO.getProperties(), Map.class);
+ return !oldProperties.equals(newFileset.properties());
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to deserialize json object:", e);
+ }
+ }
+
+ /**
+ * Convert {@link FilesetPO} to {@link FilesetEntity}
+ *
+ * @param filesetPO FilesetPO object to be converted
+ * @param namespace Namespace object to be associated with the fileset
+ * @return FilesetEntity object from FilesetPO object
+ */
+ public static FilesetEntity fromFilesetPO(FilesetPO filesetPO, Namespace namespace) {
+ try {
+ return new FilesetEntity.Builder()
+ .withId(filesetPO.getFilesetId())
+ .withName(filesetPO.getFilesetName())
+ .withNamespace(namespace)
+ .withComment(filesetPO.getFilesetVersionPO().getFilesetComment())
+ .withFilesetType(Fileset.Type.valueOf(filesetPO.getType()))
+ .withStorageLocation(filesetPO.getFilesetVersionPO().getStorageLocation())
+ .withProperties(
+ JsonUtils.anyFieldMapper()
+ .readValue(filesetPO.getFilesetVersionPO().getProperties(), Map.class))
+ .withAuditInfo(
+ JsonUtils.anyFieldMapper().readValue(filesetPO.getAuditInfo(), AuditInfo.class))
+ .build();
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to deserialize json object:", e);
+ }
+ }
+
+ /**
+ * Convert list of {@link FilesetPO} to list of {@link FilesetEntity}
+ *
+ * @param filesetPOs list of FilesetPO objects
+ * @param namespace Namespace object to be associated with the fileset
+ * @return list of FilesetEntity objects from list of FilesetPO objects
+ */
+ public static List<FilesetEntity> fromFilesetPOs(
+ List<FilesetPO> filesetPOs, Namespace namespace) {
+ return filesetPOs.stream()
+ .map(filesetPO -> POConverters.fromFilesetPO(filesetPO, namespace))
+ .collect(Collectors.toList());
+ }
}
diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/SessionUtils.java b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/SessionUtils.java
index 2d9009acfa..fb092eb14c 100644
--- a/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/SessionUtils.java
+++ b/core/src/main/java/com/datastrato/gravitino/storage/relational/utils/SessionUtils.java
@@ -34,7 +34,7 @@ public class SessionUtils {
SqlSessions.commitAndCloseSqlSession();
} catch (Throwable t) {
SqlSessions.rollbackAndCloseSqlSession();
- throw new RuntimeException(t);
+ throw t;
}
}
}
@@ -58,7 +58,7 @@ public class SessionUtils {
return result;
} catch (Throwable t) {
SqlSessions.rollbackAndCloseSqlSession();
- throw new RuntimeException(t);
+ throw t;
}
}
}
@@ -76,7 +76,7 @@ public class SessionUtils {
T mapper = SqlSessions.getMapper(mapperClazz);
consumer.accept(mapper);
} catch (Throwable t) {
- throw new RuntimeException(t);
+ throw t;
}
}
@@ -96,7 +96,7 @@ public class SessionUtils {
T mapper = SqlSessions.getMapper(mapperClazz);
return func.apply(mapper);
} catch (Throwable t) {
- throw new RuntimeException(t);
+ throw t;
} finally {
SqlSessions.closeSqlSession();
}
@@ -116,7 +116,7 @@ public class SessionUtils {
SqlSessions.commitAndCloseSqlSession();
} catch (Throwable t) {
SqlSessions.rollbackAndCloseSqlSession();
- throw new RuntimeException(t);
+ throw t;
}
}
}
diff --git a/core/src/main/resources/mysql/mysql_init.sql b/core/src/main/resources/mysql/mysql_init.sql
index 0505a93a92..87ca2dd95a 100644
--- a/core/src/main/resources/mysql/mysql_init.sql
+++ b/core/src/main/resources/mysql/mysql_init.sql
@@ -63,4 +63,39 @@ CREATE TABLE IF NOT EXISTS `table_meta` (
UNIQUE KEY `uk_sid_tn_del` (`schema_id`, `table_name`, `deleted_at`),
KEY `idx_mid` (`metalake_id`),
KEY `idx_cid` (`catalog_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'table metadata';
\ No newline at end of file
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'table metadata';
+
+CREATE TABLE IF NOT EXISTS `fileset_meta` (
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `fileset_name` VARCHAR(128) NOT NULL COMMENT 'fileset name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'fileset type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'fileset audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (`fileset_id`),
+ UNIQUE KEY `uk_sid_fn_del` (`schema_id`, `fileset_name`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'fileset metadata';
+
+CREATE TABLE IF NOT EXISTS `fileset_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `version` INT UNSIGNED NOT NULL COMMENT 'fileset info version',
+ `fileset_comment` VARCHAR(256) DEFAULT '' COMMENT 'fileset comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset properties',
+ `storage_location` MEDIUMTEXT NOT NULL COMMENT 'fileset storage location',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_fid_ver_del` (`fileset_id`, `version`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`),
+ KEY `idx_sid` (`schema_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'fileset version info';
\ No newline at end of file
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestRelationalEntityStore.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestRelationalEntityStore.java
index 18e1708447..6ea1fb514b 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/relational/TestRelationalEntityStore.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/TestRelationalEntityStore.java
@@ -28,9 +28,11 @@ import com.datastrato.gravitino.EntityStoreFactory;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.exceptions.NoSuchEntityException;
import com.datastrato.gravitino.exceptions.NonEmptyEntityException;
+import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.SchemaVersion;
import com.datastrato.gravitino.meta.TableEntity;
@@ -305,6 +307,70 @@ public class TestRelationalEntityStore {
assertEquals(overwrittenTable.auditInfo().creator(), insertedTable1.auditInfo().creator());
}
+ @Test
+ public void testFilesetPutAndGet() throws IOException {
+ BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test");
+ entityStore.put(metalake, false);
+
+ CatalogEntity catalog =
+ createCatalog(1L, "test_catalog", Namespace.ofCatalog(metalake.name()), "this is test");
+ entityStore.put(catalog, false);
+
+ SchemaEntity schema =
+ createSchema(
+ 1L,
+ "test_schema",
+ Namespace.ofSchema(metalake.name(), catalog.name()),
+ "this is schema test");
+ entityStore.put(schema, false);
+
+ FilesetEntity filesetEntity =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test",
+ "hdfs://localhost/test");
+ entityStore.put(filesetEntity, false);
+
+ FilesetEntity insertedFileset =
+ entityStore.get(
+ filesetEntity.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class);
+ assertNotNull(insertedFileset);
+ assertTrue(checkFilesetEquals(filesetEntity, insertedFileset));
+
+ // overwrite false
+ FilesetEntity duplicateFileset =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test",
+ "hdfs://localhost/test");
+ assertThrows(
+ EntityAlreadyExistsException.class, () -> entityStore.put(duplicateFileset, false));
+
+ // overwrite true
+ FilesetEntity overwrittenFileset =
+ createFileset(
+ 1L,
+ "test_fileset1",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test1",
+ "hdfs://localhost/test1");
+ entityStore.put(overwrittenFileset, true);
+ FilesetEntity insertedFileset1 =
+ entityStore.get(
+ overwrittenFileset.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class);
+
+ assertEquals(
+ 1,
+ entityStore
+ .list(insertedFileset1.namespace(), FilesetEntity.class, Entity.EntityType.FILESET)
+ .size());
+ checkFilesetEquals(overwrittenFileset, insertedFileset1);
+ }
+
@Test
public void testMetalakePutAndList() throws IOException {
BaseMetalake metalake1 = createMetalake(1L, "test_metalake1", "this is test 1");
@@ -413,7 +479,7 @@ public class TestRelationalEntityStore {
1L, "test_table1", Namespace.ofTable(metalake.name(), catalog.name(), schema.name()));
TableEntity table2 =
createTable(
- 2L, "test_schema2", Namespace.ofTable(metalake.name(), catalog.name(), schema.name()));
+ 2L, "test_table2", Namespace.ofTable(metalake.name(), catalog.name(), schema.name()));
List<TableEntity> beforeTableList =
entityStore.list(table1.namespace(), TableEntity.class, Entity.EntityType.TABLE);
@@ -432,6 +498,53 @@ public class TestRelationalEntityStore {
assertTrue(checkTableEquals(table2, tableEntities.get(1)));
}
+ @Test
+ public void testFilesetPutAndList() throws IOException {
+ BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test 1");
+ entityStore.put(metalake, false);
+
+ CatalogEntity catalog =
+ createCatalog(1L, "test_catalog", Namespace.ofCatalog(metalake.name()), "this is test");
+ entityStore.put(catalog, false);
+
+ SchemaEntity schema =
+ createSchema(
+ 1L, "test_schema", Namespace.ofSchema(metalake.name(), catalog.name()), "this is test");
+ entityStore.put(schema, false);
+
+ FilesetEntity fileset1 =
+ createFileset(
+ 1L,
+ "test_filese1",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset 1",
+ "hdfs://localhost/test1");
+ FilesetEntity fileset2 =
+ createFileset(
+ 2L,
+ "test_filese2",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset 2",
+ "hdfs://localhost/test2");
+
+ List<FilesetEntity> beforeFilesetList =
+ entityStore.list(fileset1.namespace(), FilesetEntity.class, Entity.EntityType.FILESET);
+ assertNotNull(beforeFilesetList);
+ assertEquals(0, beforeFilesetList.size());
+
+ entityStore.put(fileset1, false);
+ entityStore.put(fileset2, false);
+ List<FilesetEntity> filesetEntities =
+ entityStore.list(fileset1.namespace(), FilesetEntity.class, Entity.EntityType.FILESET)
+ .stream()
+ .sorted(Comparator.comparing(FilesetEntity::id))
+ .collect(Collectors.toList());
+ assertNotNull(filesetEntities);
+ assertEquals(2, filesetEntities.size());
+ assertTrue(checkFilesetEquals(fileset1, filesetEntities.get(0)));
+ assertTrue(checkFilesetEquals(fileset2, filesetEntities.get(1)));
+ }
+
@Test
public void testMetalakePutAndDelete() throws IOException, InterruptedException {
BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test");
@@ -474,6 +587,15 @@ public class TestRelationalEntityStore {
Namespace.ofTable(metalake1.name(), subCatalog.name(), subSchema.name()));
entityStore.put(subTable, false);
+ FilesetEntity subFileset =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake1.name(), subCatalog.name(), subSchema.name()),
+ "test cascade deleted",
+ "hdfs://localhost/test");
+ entityStore.put(subFileset, false);
+
// cascade is false
assertThrows(
NonEmptyEntityException.class,
@@ -485,6 +607,7 @@ public class TestRelationalEntityStore {
assertFalse(entityStore.exists(subCatalog.nameIdentifier(), Entity.EntityType.CATALOG));
assertFalse(entityStore.exists(subSchema.nameIdentifier(), Entity.EntityType.SCHEMA));
assertFalse(entityStore.exists(subTable.nameIdentifier(), Entity.EntityType.TABLE));
+ assertFalse(entityStore.exists(subFileset.nameIdentifier(), Entity.EntityType.FILESET));
}
@Test
@@ -530,6 +653,15 @@ public class TestRelationalEntityStore {
Namespace.ofTable(metalake.name(), catalog1.name(), subSchema.name()));
entityStore.put(subTable, false);
+ FilesetEntity subFileset =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog1.name(), subSchema.name()),
+ "test cascade deleted",
+ "hdfs://localhost/test");
+ entityStore.put(subFileset, false);
+
// cascade is false
assertThrows(
NonEmptyEntityException.class,
@@ -540,6 +672,7 @@ public class TestRelationalEntityStore {
assertFalse(entityStore.exists(catalog1.nameIdentifier(), Entity.EntityType.CATALOG));
assertFalse(entityStore.exists(subSchema.nameIdentifier(), Entity.EntityType.SCHEMA));
assertFalse(entityStore.exists(subTable.nameIdentifier(), Entity.EntityType.TABLE));
+ assertFalse(entityStore.exists(subFileset.nameIdentifier(), Entity.EntityType.FILESET));
}
@Test
@@ -582,6 +715,15 @@ public class TestRelationalEntityStore {
1L, "test_table", Namespace.ofTable(metalake.name(), catalog.name(), schema1.name()));
entityStore.put(subTable, false);
+ FilesetEntity subFileset =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema1.name()),
+ "test cascade deleted",
+ "hdfs://localhost/test");
+ entityStore.put(subFileset, false);
+
// cascade is false
assertThrows(
NonEmptyEntityException.class,
@@ -591,10 +733,11 @@ public class TestRelationalEntityStore {
entityStore.delete(schema1.nameIdentifier(), Entity.EntityType.SCHEMA, true);
assertFalse(entityStore.exists(schema1.nameIdentifier(), Entity.EntityType.SCHEMA));
assertFalse(entityStore.exists(subTable.nameIdentifier(), Entity.EntityType.TABLE));
+ assertFalse(entityStore.exists(subFileset.nameIdentifier(), Entity.EntityType.FILESET));
}
@Test
- public void testTablePutAndDelete() throws IOException, InterruptedException {
+ public void testTablePutAndDelete() throws IOException {
BaseMetalake metalake = createMetalake(3L, "test_metalake", "this is test");
entityStore.put(metalake, false);
@@ -619,19 +762,40 @@ public class TestRelationalEntityStore {
assertThrows(
NoSuchEntityException.class,
() -> entityStore.get(table.nameIdentifier(), Entity.EntityType.TABLE, TableEntity.class));
+ }
- // sleep 1s to make delete_at seconds differently
- Thread.sleep(1000);
+ @Test
+ public void testFilesetPutAndDelete() throws IOException, InterruptedException {
+ BaseMetalake metalake = createMetalake(3L, "test_metalake", "this is test");
+ entityStore.put(metalake, false);
- // test cascade delete
- TableEntity table1 =
- createTable(
- 3L, "test_table1", Namespace.ofTable(metalake.name(), catalog.name(), schema.name()));
- entityStore.put(table1, false);
+ CatalogEntity catalog =
+ createCatalog(2L, "test_catalog", Namespace.ofCatalog(metalake.name()), "this is test");
+ entityStore.put(catalog, false);
- // cascade is true
- entityStore.delete(table1.nameIdentifier(), Entity.EntityType.TABLE, true);
- assertFalse(entityStore.exists(table1.nameIdentifier(), Entity.EntityType.TABLE));
+ SchemaEntity schema =
+ createSchema(
+ 2L, "test_schema", Namespace.ofSchema(metalake.name(), catalog.name()), "this is test");
+ entityStore.put(schema, false);
+
+ FilesetEntity fileset =
+ createFileset(
+ 2L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test",
+ "hdfs://localhost/test");
+ entityStore.put(fileset, false);
+
+ assertNotNull(
+ entityStore.get(fileset.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class));
+ entityStore.delete(fileset.nameIdentifier(), Entity.EntityType.FILESET, false);
+
+ assertThrows(
+ NoSuchEntityException.class,
+ () ->
+ entityStore.get(
+ fileset.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class));
}
@Test
@@ -986,6 +1150,153 @@ public class TestRelationalEntityStore {
}));
}
+ @Test
+ public void testFilesetPutAndUpdate() throws IOException {
+ BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test");
+ entityStore.put(metalake, false);
+
+ CatalogEntity catalog =
+ createCatalog(
+ 1L, "test_catalog", Namespace.ofCatalog(metalake.name()), "this is catalog test");
+ entityStore.put(catalog, false);
+
+ SchemaEntity schema =
+ createSchema(
+ 1L,
+ "test_schema",
+ Namespace.ofSchema(metalake.name(), catalog.name()),
+ "this is schema test");
+ entityStore.put(schema, false);
+
+ FilesetEntity fileset =
+ createFileset(
+ 1L,
+ "test_fileset",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test",
+ "hdfs://localhost/test");
+ entityStore.put(fileset, false);
+
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ entityStore.update(
+ fileset.nameIdentifier(),
+ FilesetEntity.class,
+ Entity.EntityType.FILESET,
+ f -> {
+ FilesetEntity.Builder builder =
+ new FilesetEntity.Builder()
+ // Change the id, which is not allowed
+ .withId(2L)
+ .withName("test_fileset2")
+ .withNamespace(
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()))
+ .withComment(f.comment())
+ .withProperties(f.properties())
+ .withStorageLocation(f.storageLocation())
+ .withFilesetType(f.filesetType())
+ .withAuditInfo(f.auditInfo());
+ return builder.build();
+ }));
+
+ AuditInfo changedAuditInfo =
+ AuditInfo.builder().withCreator("changed_creator").withCreateTime(Instant.now()).build();
+ // update version fields and normal fields
+ FilesetEntity updatedFileset =
+ entityStore.update(
+ fileset.nameIdentifier(),
+ FilesetEntity.class,
+ Entity.EntityType.FILESET,
+ f -> {
+ FilesetEntity.Builder builder =
+ new FilesetEntity.Builder()
+ .withId(f.id())
+ .withName("test_fileset2")
+ .withNamespace(
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()))
+ .withFilesetType(f.filesetType())
+ .withComment("this is fileset test 2")
+ .withStorageLocation("hdfs://localhost/test2")
+ .withProperties(f.properties())
+ .withAuditInfo(changedAuditInfo);
+ return builder.build();
+ });
+
+ FilesetEntity storedFileset =
+ entityStore.get(
+ updatedFileset.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class);
+
+ assertEquals(fileset.id(), storedFileset.id());
+ assertEquals("test_fileset2", storedFileset.name());
+ assertEquals(changedAuditInfo.creator(), storedFileset.auditInfo().creator());
+ assertEquals("this is fileset test 2", storedFileset.comment());
+ assertEquals("hdfs://localhost/test2", storedFileset.storageLocation());
+
+ FilesetEntity fileset3 =
+ createFileset(
+ 3L,
+ "test_fileset3",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is fileset test 3",
+ "hdfs://localhost/test3");
+ entityStore.put(fileset3, false);
+
+ assertThrows(
+ EntityAlreadyExistsException.class,
+ () ->
+ entityStore.update(
+ fileset3.nameIdentifier(),
+ FilesetEntity.class,
+ Entity.EntityType.FILESET,
+ f -> {
+ FilesetEntity.Builder builder =
+ new FilesetEntity.Builder()
+ .withId(fileset3.id())
+ // fileset name already exists
+ .withName("test_fileset2")
+ .withNamespace(
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()))
+ .withFilesetType(f.filesetType())
+ .withStorageLocation(f.storageLocation())
+ .withComment(f.comment())
+ .withProperties(f.properties())
+ .withAuditInfo(f.auditInfo());
+ return builder.build();
+ }));
+
+ // only update normal fields
+ FilesetEntity updatedFileset2 =
+ entityStore.update(
+ fileset3.nameIdentifier(),
+ FilesetEntity.class,
+ Entity.EntityType.FILESET,
+ f -> {
+ FilesetEntity.Builder builder =
+ new FilesetEntity.Builder()
+ .withId(f.id())
+ .withName("test_fileset4")
+ .withNamespace(
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()))
+ .withFilesetType(f.filesetType())
+ .withComment(f.comment())
+ .withStorageLocation(f.storageLocation())
+ .withProperties(f.properties())
+ .withAuditInfo(changedAuditInfo);
+ return builder.build();
+ });
+
+ FilesetEntity storedFileset2 =
+ entityStore.get(
+ updatedFileset2.nameIdentifier(), Entity.EntityType.FILESET, FilesetEntity.class);
+
+ assertEquals(fileset3.id(), storedFileset2.id());
+ assertEquals("test_fileset4", storedFileset2.name());
+ assertEquals(changedAuditInfo.creator(), storedFileset2.auditInfo().creator());
+ assertEquals(fileset3.comment(), storedFileset2.comment());
+ assertEquals(fileset3.storageLocation(), storedFileset2.storageLocation());
+ }
+
@Test
public void testMetalakePutAndExists() throws IOException {
BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test");
@@ -1044,6 +1355,32 @@ public class TestRelationalEntityStore {
assertTrue(entityStore.exists(table.nameIdentifier(), Entity.EntityType.TABLE));
}
+ @Test
+ public void testFilesetPutAndExists() throws IOException {
+ BaseMetalake metalake = createMetalake(1L, "test_metalake", "this is test");
+ entityStore.put(metalake, false);
+
+ CatalogEntity catalog =
+ createCatalog(1L, "test_catalog", Namespace.ofCatalog(metalake.name()), "this is test");
+ entityStore.put(catalog, false);
+
+ SchemaEntity schema =
+ createSchema(
+ 1L, "test_schema", Namespace.ofSchema(metalake.name(), catalog.name()), "this is test");
+ entityStore.put(schema, false);
+
+ FilesetEntity fileset =
+ createFileset(
+ 1L,
+ "test_table",
+ Namespace.ofFileset(metalake.name(), catalog.name(), schema.name()),
+ "this is test",
+ "hdfs://localhost/test");
+ entityStore.put(fileset, false);
+
+ assertTrue(entityStore.exists(fileset.nameIdentifier(), Entity.EntityType.FILESET));
+ }
+
private static BaseMetalake createMetalake(Long id, String name, String comment) {
AuditInfo auditInfo =
AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build();
@@ -1136,6 +1473,34 @@ public class TestRelationalEntityStore {
&& expected.auditInfo().equals(actual.auditInfo());
}
+ private static FilesetEntity createFileset(
+ Long id, String name, Namespace namespace, String comment, String location) {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build();
+ return new FilesetEntity.Builder()
+ .withId(id)
+ .withName(name)
+ .withNamespace(namespace)
+ .withFilesetType(Fileset.Type.MANAGED)
+ .withComment(comment)
+ .withAuditInfo(auditInfo)
+ .withStorageLocation(location)
+ .withProperties(new HashMap<>())
+ .build();
+ }
+
+ private static boolean checkFilesetEquals(FilesetEntity expected, FilesetEntity actual) {
+ return expected.id().equals(actual.id())
+ && expected.name().equals(actual.name())
+ && expected.filesetType() == actual.filesetType()
+ && expected.comment().equals(actual.comment())
+ && expected.storageLocation().equals(actual.storageLocation())
+ && expected.properties() != null
+ && expected.properties().equals(actual.properties())
+ && expected.namespace().equals(actual.namespace())
+ && expected.auditInfo().equals(actual.auditInfo());
+ }
+
private static void truncateAllTables() {
try (SqlSession sqlSession =
SqlSessionFactoryHelper.getInstance().getSqlSessionFactory().openSession(true)) {
diff --git a/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java b/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java
index 87d95c93c5..3b67c529d1 100644
--- a/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java
+++ b/core/src/test/java/com/datastrato/gravitino/storage/relational/utils/TestPOConverters.java
@@ -13,10 +13,13 @@ import com.datastrato.gravitino.json.JsonUtils;
import com.datastrato.gravitino.meta.AuditInfo;
import com.datastrato.gravitino.meta.BaseMetalake;
import com.datastrato.gravitino.meta.CatalogEntity;
+import com.datastrato.gravitino.meta.FilesetEntity;
import com.datastrato.gravitino.meta.SchemaEntity;
import com.datastrato.gravitino.meta.SchemaVersion;
import com.datastrato.gravitino.meta.TableEntity;
import com.datastrato.gravitino.storage.relational.po.CatalogPO;
+import com.datastrato.gravitino.storage.relational.po.FilesetPO;
+import com.datastrato.gravitino.storage.relational.po.FilesetVersionPO;
import com.datastrato.gravitino.storage.relational.po.MetalakePO;
import com.datastrato.gravitino.storage.relational.po.SchemaPO;
import com.datastrato.gravitino.storage.relational.po.TablePO;
@@ -114,6 +117,34 @@ public class TestPOConverters {
assertEquals(expectedTable.auditInfo().creator(), convertedTable.auditInfo().creator());
}
+ @Test
+ public void testFromFilesetPO() throws JsonProcessingException {
+ FilesetVersionPO filesetVersionPO =
+ createFilesetVersionPO(
+ 1L, 1L, 1L, 1L, 1L, "this is test", "hdfs://localhost/test", new HashMap<>());
+ FilesetPO filesetPO = createFilesetPO(1L, "test", 1L, 1L, 1L, 1L, filesetVersionPO);
+
+ FilesetEntity expectedFileset =
+ createFileset(
+ 1L,
+ "test",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test",
+ "hdfs://localhost/test",
+ new HashMap<>());
+
+ FilesetEntity convertedFileset =
+ POConverters.fromFilesetPO(
+ filesetPO, Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"));
+
+ // Assert
+ assertEquals(expectedFileset.id(), convertedFileset.id());
+ assertEquals(expectedFileset.name(), convertedFileset.name());
+ assertEquals(expectedFileset.namespace(), convertedFileset.namespace());
+ assertEquals(expectedFileset.auditInfo().creator(), convertedFileset.auditInfo().creator());
+ assertEquals(expectedFileset.storageLocation(), convertedFileset.storageLocation());
+ }
+
@Test
public void testFromMetalakePOs() throws JsonProcessingException {
MetalakePO metalakePO1 = createMetalakePO(1L, "test", "this is test");
@@ -233,6 +264,55 @@ public class TestPOConverters {
}
}
+ @Test
+ public void testFromFilesetPOs() throws JsonProcessingException {
+ FilesetVersionPO filesetVersionPO1 =
+ createFilesetVersionPO(
+ 1L, 1L, 1L, 1L, 1L, "this is test1", "hdfs://localhost/test1", new HashMap<>());
+ FilesetPO filesetPO1 = createFilesetPO(1L, "test1", 1L, 1L, 1L, 1L, filesetVersionPO1);
+
+ FilesetVersionPO filesetVersionPO2 =
+ createFilesetVersionPO(
+ 2L, 1L, 1L, 1L, 2L, "this is test2", "hdfs://localhost/test2", new HashMap<>());
+ FilesetPO filesetPO2 = createFilesetPO(2L, "test2", 1L, 1L, 1L, 2L, filesetVersionPO2);
+
+ List<FilesetPO> filesetPOs = new ArrayList<>(Arrays.asList(filesetPO1, filesetPO2));
+ List<FilesetEntity> convertedFilesets =
+ POConverters.fromFilesetPOs(
+ filesetPOs, Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"));
+
+ FilesetEntity expectedFileset1 =
+ createFileset(
+ 1L,
+ "test1",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test1",
+ "hdfs://localhost/test1",
+ new HashMap<>());
+ FilesetEntity expectedFileset2 =
+ createFileset(
+ 2L,
+ "test2",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test2",
+ "hdfs://localhost/test2",
+ new HashMap<>());
+ List<FilesetEntity> expectedFilesets =
+ new ArrayList<>(Arrays.asList(expectedFileset1, expectedFileset2));
+
+ // Assert
+ int index = 0;
+ for (FilesetEntity fileset : convertedFilesets) {
+ assertEquals(expectedFilesets.get(index).id(), fileset.id());
+ assertEquals(expectedFilesets.get(index).name(), fileset.name());
+ assertEquals(expectedFilesets.get(index).namespace(), fileset.namespace());
+ assertEquals(
+ expectedFilesets.get(index).auditInfo().creator(), fileset.auditInfo().creator());
+ assertEquals(expectedFilesets.get(index).storageLocation(), fileset.storageLocation());
+ index++;
+ }
+ }
+
@Test
public void testInitMetalakePOVersion() {
BaseMetalake metalake = createMetalake(1L, "test", "this is test");
@@ -280,6 +360,28 @@ public class TestPOConverters {
assertEquals(0, initPO.getDeletedAt());
}
+ @Test
+ public void testInitFilesetPOVersion() {
+ FilesetEntity filesetEntity =
+ createFileset(
+ 1L,
+ "test",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test",
+ "hdfs://localhost/test",
+ new HashMap<>());
+ FilesetPO.Builder builder = new FilesetPO.Builder();
+ builder.withMetalakeId(1L);
+ builder.withCatalogId(1L);
+ builder.withSchemaId(1L);
+ FilesetPO initPO = POConverters.initializeFilesetPOWithVersion(filesetEntity, builder);
+ assertEquals(1, initPO.getCurrentVersion());
+ assertEquals(1, initPO.getLastVersion());
+ assertEquals(0, initPO.getDeletedAt());
+ assertEquals(1, initPO.getFilesetVersionPO().getVersion());
+ assertEquals("hdfs://localhost/test", initPO.getFilesetVersionPO().getStorageLocation());
+ }
+
@Test
public void testUpdateMetalakePOVersion() {
BaseMetalake metalake = createMetalake(1L, "test", "this is test");
@@ -343,6 +445,76 @@ public class TestPOConverters {
assertEquals("test", updatePO.getTableName());
}
+ @Test
+ public void testUpdateFilesetPOVersion() throws JsonProcessingException {
+ Map<String, String> properties = new HashMap<>();
+ properties.put("key", "value");
+ FilesetEntity filesetEntity =
+ createFileset(
+ 1L,
+ "test",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test",
+ "hdfs://localhost/test",
+ properties);
+
+ Map<String, String> updateProperties = new HashMap<>();
+ updateProperties.put("key", "value1");
+ FilesetEntity updatedFileset =
+ createFileset(
+ 1L,
+ "test",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test",
+ "hdfs://localhost/test",
+ updateProperties);
+
+ FilesetEntity updatedFileset1 =
+ createFileset(
+ 1L,
+ "test1",
+ Namespace.ofFileset("test_metalake", "test_catalog", "test_schema"),
+ "this is test",
+ "hdfs://localhost/test",
+ properties);
+
+ FilesetPO.Builder builder = new FilesetPO.Builder();
+ builder.withMetalakeId(1L);
+ builder.withCatalogId(1L);
+ builder.withSchemaId(1L);
+ FilesetPO initPO = POConverters.initializeFilesetPOWithVersion(filesetEntity, builder);
+
+ // map has updated
+ boolean checkNeedUpdate1 =
+ POConverters.checkFilesetVersionNeedUpdate(initPO.getFilesetVersionPO(), updatedFileset);
+ FilesetPO updatePO1 =
+ POConverters.updateFilesetPOWithVersion(initPO, updatedFileset, checkNeedUpdate1);
+ assertEquals(1, initPO.getCurrentVersion());
+ assertEquals(1, initPO.getLastVersion());
+ assertEquals(0, initPO.getDeletedAt());
+ assertEquals(
+ updatedFileset.storageLocation(), updatePO1.getFilesetVersionPO().getStorageLocation());
+ assertEquals(2, updatePO1.getCurrentVersion());
+ assertEquals(2, updatePO1.getLastVersion());
+ assertEquals(2, updatePO1.getFilesetVersionPO().getVersion());
+ Map<String, String> updatedProperties =
+ JsonUtils.anyFieldMapper()
+ .readValue(updatePO1.getFilesetVersionPO().getProperties(), Map.class);
+ assertEquals("value1", updatedProperties.get("key"));
+
+ // will not update version, but update the fileset name
+ boolean checkNeedUpdate2 =
+ POConverters.checkFilesetVersionNeedUpdate(initPO.getFilesetVersionPO(), updatedFileset1);
+ FilesetPO updatePO2 =
+ POConverters.updateFilesetPOWithVersion(initPO, updatedFileset1, checkNeedUpdate2);
+ assertEquals(
+ filesetEntity.storageLocation(), updatePO2.getFilesetVersionPO().getStorageLocation());
+ assertEquals(1, updatePO2.getCurrentVersion());
+ assertEquals(1, updatePO2.getLastVersion());
+ assertEquals(1, updatePO2.getFilesetVersionPO().getVersion());
+ assertEquals("test1", updatePO2.getFilesetName());
+ }
+
private static BaseMetalake createMetalake(Long id, String name, String comment) {
AuditInfo auditInfo =
AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
@@ -481,4 +653,76 @@ public class TestPOConverters {
.withDeletedAt(0L)
.build();
}
+
+ private static FilesetEntity createFileset(
+ Long id,
+ String name,
+ Namespace namespace,
+ String comment,
+ String storageLocation,
+ Map<String, String> properties) {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
+ return new FilesetEntity.Builder()
+ .withId(id)
+ .withName(name)
+ .withNamespace(namespace)
+ .withFilesetType(com.datastrato.gravitino.file.Fileset.Type.MANAGED)
+ .withStorageLocation(storageLocation)
+ .withProperties(properties)
+ .withComment(comment)
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
+ private static FilesetPO createFilesetPO(
+ Long id,
+ String name,
+ Long metalakeId,
+ Long catalogId,
+ Long schemaId,
+ Long filesetId,
+ FilesetVersionPO filesetVersionPO)
+ throws JsonProcessingException {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
+ return new FilesetPO.Builder()
+ .withFilesetId(id)
+ .withFilesetName(name)
+ .withMetalakeId(metalakeId)
+ .withCatalogId(catalogId)
+ .withSchemaId(schemaId)
+ .withFilesetId(filesetId)
+ .withType(com.datastrato.gravitino.file.Fileset.Type.MANAGED.name())
+ .withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(auditInfo))
+ .withCurrentVersion(1L)
+ .withLastVersion(1L)
+ .withDeletedAt(0L)
+ .withFilesetVersionPO(filesetVersionPO)
+ .build();
+ }
+
+ private static FilesetVersionPO createFilesetVersionPO(
+ Long id,
+ Long metalakeId,
+ Long catalogId,
+ Long schemaId,
+ Long filesetId,
+ String comment,
+ String storageLocation,
+ Map<String, String> properties)
+ throws JsonProcessingException {
+ return new FilesetVersionPO.Builder()
+ .withId(id)
+ .withMetalakeId(metalakeId)
+ .withCatalogId(catalogId)
+ .withSchemaId(schemaId)
+ .withFilesetId(filesetId)
+ .withFilesetComment(comment)
+ .withStorageLocation(storageLocation)
+ .withProperties(JsonUtils.anyFieldMapper().writeValueAsString(properties))
+ .withVersion(1L)
+ .withDeletedAt(0L)
+ .build();
+ }
}
diff --git a/core/src/test/resources/h2/h2-init.sql b/core/src/test/resources/h2/h2-init.sql
index ec7a9be332..3699e419ff 100644
--- a/core/src/test/resources/h2/h2-init.sql
+++ b/core/src/test/resources/h2/h2-init.sql
@@ -67,4 +67,42 @@ CREATE TABLE IF NOT EXISTS `table_meta` (
-- Aliases are used here, and indexes with the same name in H2 can only be created once.
KEY idx_tmid (metalake_id),
KEY idx_tcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_meta` (
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `fileset_name` VARCHAR(128) NOT NULL COMMENT 'fileset name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'fileset type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'fileset audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (fileset_id),
+ CONSTRAINT uk_sid_fn_del UNIQUE (schema_id, fileset_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fmid (metalake_id),
+ KEY idx_fcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `version` INT UNSIGNED NOT NULL COMMENT 'fileset info version',
+ `fileset_comment` VARCHAR(256) DEFAULT '' COMMENT 'fileset comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset properties',
+ `storage_location` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset storage location',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (id),
+ CONSTRAINT uk_fid_ver_del UNIQUE (fileset_id, version, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fvmid (metalake_id),
+ KEY idx_fvcid (catalog_id)
) ENGINE=InnoDB;
\ No newline at end of file