From 9d192b29b44524d5a4cc695d914f90805d23978b Mon Sep 17 00:00:00 2001 From: yuqi Date: Sat, 7 Sep 2024 04:36:38 +0800 Subject: [PATCH] Move PostgreSQL related mapper to the new package postgresql. --- .../mapper/CatalogMetaSQLProviderFactory.java | 85 +------------ .../mapper/FilesetMetaSQLProviderFactory.java | 69 +---------- .../FilesetVersionSQLProviderFactory.java | 77 +----------- .../mapper/GroupMetaSQLProviderFactory.java | 47 +------ .../GroupRoleRelSQLProviderFactory.java | 49 +------- .../MetalakeMetaSQLProviderFactory.java | 67 +--------- .../mapper/OwnerMetaSQLProviderFactory.java | 92 +------------- .../mapper/RoleMetaSQLProviderFactory.java | 48 +------- .../mapper/SchemaMetaSQLProviderFactory.java | 61 +-------- .../SecurableObjectSQLProviderFactory.java | 26 +--- .../mapper/TableMetaSQLProviderFactory.java | 67 +--------- .../mapper/TagMetaSQLProviderFactory.java | 78 +----------- ...agMetadataObjectRelSQLProviderFactory.java | 65 +--------- .../mapper/TopicMetaSQLProviderFactory.java | 71 +---------- .../mapper/UserMetaSQLProviderFactory.java | 47 +------ .../mapper/UserRoleRelSQLProviderFactory.java | 76 +----------- .../CatalogMetaPostgreSQLProvider.java | 106 ++++++++++++++++ .../FilesetMetaPostgreSQLProvider.java | 89 ++++++++++++++ .../FilesetVersionPostgreSQLProvider.java | 97 +++++++++++++++ .../GroupMetaPostgreSQLProvider.java | 67 ++++++++++ .../GroupRoleRelPostgreSQLProvider.java | 69 +++++++++++ .../MetalakeMetaPostgreSQLProvider.java | 88 +++++++++++++ .../OwnerMetaPostgreSQLProvider.java | 116 ++++++++++++++++++ .../RoleMetaPostgreSQLProvider.java | 68 ++++++++++ .../SchemaMetaPostgreSQLProvider.java | 81 ++++++++++++ .../SecurableObjectPostgreSQLProvider.java | 45 +++++++ .../TableMetaPostgreSQLProvider.java | 87 +++++++++++++ .../postgresql/TagMetaPostgreSQLProvider.java | 100 +++++++++++++++ ...agMetadataObjectRelPostgreSQLProvider.java | 86 +++++++++++++ .../TopicMetaPostgreSQLProvider.java | 92 ++++++++++++++ .../UserMetaPostgreSQLProvider.java | 67 ++++++++++ .../UserRoleRelPostgreSQLProvider.java | 98 +++++++++++++++ 32 files changed, 1372 insertions(+), 1009 deletions(-) create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/CatalogMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetVersionPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupRoleRelPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/MetalakeMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/OwnerMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/RoleMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SchemaMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SecurableObjectPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TableMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetadataObjectRelPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TopicMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserMetaPostgreSQLProvider.java create mode 100644 core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserRoleRelPostgreSQLProvider.java diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java index 14b3489f280..632681c5f0c 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java @@ -19,11 +19,10 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper.TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.CatalogMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.CatalogPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -52,88 +51,6 @@ static class CatalogMetaMySQLProvider extends CatalogMetaBaseSQLProvider {} static class CatalogMetaH2Provider extends CatalogMetaBaseSQLProvider {} - static class CatalogMetaPostgreSQLProvider extends CatalogMetaBaseSQLProvider { - - @Override - public String softDeleteCatalogMetasByCatalogId(Long catalogId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - - @Override - public String softDeleteCatalogMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertCatalogMetaOnDuplicateKeyUpdate(CatalogPO catalogPO) { - return "INSERT INTO " - + TABLE_NAME - + "(catalog_id, catalog_name, metalake_id," - + " type, provider, catalog_comment, properties, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{catalogMeta.catalogId}," - + " #{catalogMeta.catalogName}," - + " #{catalogMeta.metalakeId}," - + " #{catalogMeta.type}," - + " #{catalogMeta.provider}," - + " #{catalogMeta.catalogComment}," - + " #{catalogMeta.properties}," - + " #{catalogMeta.auditInfo}," - + " #{catalogMeta.currentVersion}," - + " #{catalogMeta.lastVersion}," - + " #{catalogMeta.deletedAt}" - + " )" - + " ON CONFLICT(catalog_id) DO UPDATE SET" - + " catalog_name = #{catalogMeta.catalogName}," - + " metalake_id = #{catalogMeta.metalakeId}," - + " type = #{catalogMeta.type}," - + " provider = #{catalogMeta.provider}," - + " catalog_comment = #{catalogMeta.catalogComment}," - + " properties = #{catalogMeta.properties}," - + " audit_info = #{catalogMeta.auditInfo}," - + " current_version = #{catalogMeta.currentVersion}," - + " last_version = #{catalogMeta.lastVersion}," - + " deleted_at = #{catalogMeta.deletedAt}"; - } - - public String updateCatalogMeta( - @Param("newCatalogMeta") CatalogPO newCatalogPO, - @Param("oldCatalogMeta") CatalogPO oldCatalogPO) { - return "UPDATE " - + TABLE_NAME - + " SET catalog_name = #{newCatalogMeta.catalogName}," - + " metalake_id = #{newCatalogMeta.metalakeId}," - + " type = #{newCatalogMeta.type}," - + " provider = #{newCatalogMeta.provider}," - + " catalog_comment = #{newCatalogMeta.catalogComment}," - + " properties = #{newCatalogMeta.properties}," - + " audit_info = #{newCatalogMeta.auditInfo}," - + " current_version = #{newCatalogMeta.currentVersion}," - + " last_version = #{newCatalogMeta.lastVersion}," - + " deleted_at = #{newCatalogMeta.deletedAt}" - + " WHERE catalog_id = #{oldCatalogMeta.catalogId}" - + " AND catalog_name = #{oldCatalogMeta.catalogName}" - + " AND metalake_id = #{oldCatalogMeta.metalakeId}" - + " AND type = #{oldCatalogMeta.type}" - + " AND provider = #{oldCatalogMeta.provider}" - + " AND (catalog_comment = #{oldCatalogMeta.catalogComment} " - + " OR (CAST(catalog_comment AS VARCHAR) IS NULL AND " - + " CAST(#{oldCatalogMeta.catalogComment} AS VARCHAR) IS NULL))" - + " AND properties = #{oldCatalogMeta.properties}" - + " AND audit_info = #{oldCatalogMeta.auditInfo}" - + " AND current_version = #{oldCatalogMeta.currentVersion}" - + " AND last_version = #{oldCatalogMeta.lastVersion}" - + " AND deleted_at = 0"; - } - } - public static String listCatalogPOsByMetalakeId(@Param("metalakeId") Long metalakeId) { return getProvider().listCatalogPOsByMetalakeId(metalakeId); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetMetaSQLProviderFactory.java index 2b643cbd28f..b41237e2a79 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetMetaSQLProviderFactory.java @@ -19,11 +19,10 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper.META_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.FilesetMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.FilesetPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -51,72 +50,6 @@ static class FilesetMetaMySQLProvider extends FilesetMetaBaseSQLProvider {} static class FilesetMetaH2Provider extends FilesetMetaBaseSQLProvider {} - static class FilesetMetaPostgreSQLProvider extends FilesetMetaBaseSQLProvider { - - @Override - public String softDeleteFilesetMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + META_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetMetasByCatalogId(Long catalogId) { - return "UPDATE " - + META_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetMetasBySchemaId(Long schemaId) { - return "UPDATE " - + META_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetMetasByFilesetId(Long filesetId) { - return "UPDATE " - + META_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE fileset_id = #{filesetId} AND deleted_at = 0"; - } - - @Override - public String insertFilesetMetaOnDuplicateKeyUpdate(FilesetPO filesetPO) { - return "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 CONFLICT(fileset_id) DO UPDATE SET" - + " 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}"; - } - } - public static String listFilesetPOsBySchemaId(@Param("schemaId") Long schemaId) { return getProvider().listFilesetPOsBySchemaId(schemaId); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetVersionSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetVersionSQLProviderFactory.java index ace3f128c12..4029c2cb055 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetVersionSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/FilesetVersionSQLProviderFactory.java @@ -18,11 +18,10 @@ * under the License. */ -import static org.apache.gravitino.storage.relational.mapper.FilesetVersionMapper.VERSION_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.FilesetVersionPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.FilesetVersionPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -50,80 +49,6 @@ static class FilesetVersionMySQLProvider extends FilesetVersionBaseSQLProvider { static class FilesetVersionH2Provider extends FilesetVersionBaseSQLProvider {} - static class FilesetVersionPostgreSQLProvider extends FilesetVersionBaseSQLProvider { - - @Override - public String softDeleteFilesetVersionsByMetalakeId(Long metalakeId) { - return "UPDATE " - + VERSION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetVersionsByCatalogId(Long catalogId) { - return "UPDATE " - + VERSION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetVersionsBySchemaId(Long schemaId) { - return "UPDATE " - + VERSION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetVersionsByFilesetId(Long filesetId) { - return "UPDATE " - + VERSION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE fileset_id = #{filesetId} AND deleted_at = 0"; - } - - @Override - public String softDeleteFilesetVersionsByRetentionLine( - Long filesetId, long versionRetentionLine, int limit) { - return "UPDATE " - + VERSION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE fileset_id = #{filesetId} AND version <= #{versionRetentionLine} AND deleted_at = 0 LIMIT #{limit}"; - } - - @Override - public String insertFilesetVersionOnDuplicateKeyUpdate(FilesetVersionPO filesetVersionPO) { - return "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 CONFLICT(fileset_id, version, deleted_at) DO UPDATE SET" - + " 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}"; - } - } - public static String insertFilesetVersion( @Param("filesetVersion") FilesetVersionPO filesetVersionPO) { return getProvider().insertFilesetVersion(filesetVersionPO); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupMetaSQLProviderFactory.java index a7f0ee2cb9e..2769bf1d959 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupMetaSQLProviderFactory.java @@ -18,11 +18,10 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.GroupMetaMapper.GROUP_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.GroupMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.GroupPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -50,50 +49,6 @@ static class GroupMetaMySQLProvider extends GroupMetaBaseSQLProvider {} static class GroupMetaH2Provider extends GroupMetaBaseSQLProvider {} - static class GroupMetaPostgreSQLProvider extends GroupMetaBaseSQLProvider { - - @Override - public String softDeleteGroupMetaByGroupId(Long groupId) { - return "UPDATE " - + GROUP_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE group_id = #{groupId} AND deleted_at = 0"; - } - - @Override - public String softDeleteGroupMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + GROUP_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertGroupMetaOnDuplicateKeyUpdate(GroupPO groupPO) { - return "INSERT INTO " - + GROUP_TABLE_NAME - + "(group_id, group_name," - + "metalake_id, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{groupMeta.groupId}," - + " #{groupMeta.groupName}," - + " #{groupMeta.metalakeId}," - + " #{groupMeta.auditInfo}," - + " #{groupMeta.currentVersion}," - + " #{groupMeta.lastVersion}," - + " #{groupMeta.deletedAt}" - + " )" - + " ON CONFLICT(group_id) DO UPDATE SET" - + " group_name = #{groupMeta.groupName}," - + " metalake_id = #{groupMeta.metalakeId}," - + " audit_info = #{groupMeta.auditInfo}," - + " current_version = #{groupMeta.currentVersion}," - + " last_version = #{groupMeta.lastVersion}," - + " deleted_at = #{groupMeta.deletedAt}"; - } - } - public static String selectGroupIdBySchemaIdAndName( @Param("metalakeId") Long metalakeId, @Param("groupName") String name) { return getProvider().selectGroupIdBySchemaIdAndName(metalakeId, name); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupRoleRelSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupRoleRelSQLProviderFactory.java index 5431315fbb1..6d2ff176bd1 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupRoleRelSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/GroupRoleRelSQLProviderFactory.java @@ -18,13 +18,11 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.GroupRoleRelMapper.GROUP_ROLE_RELATION_TABLE_NAME; -import static org.apache.gravitino.storage.relational.mapper.GroupRoleRelMapper.GROUP_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.GroupRoleRelPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.GroupRoleRelPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -53,51 +51,6 @@ static class GroupRoleRelMySQLProvider extends GroupRoleRelBaseSQLProvider {} static class GroupRoleRelH2Provider extends GroupRoleRelBaseSQLProvider {} - static class GroupRoleRelPostgreSQLProvider extends GroupRoleRelBaseSQLProvider { - - @Override - public String softDeleteGroupRoleRelByGroupId(Long groupId) { - return "UPDATE " - + GROUP_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE group_id = #{groupId} AND deleted_at = 0"; - } - - @Override - public String softDeleteGroupRoleRelByGroupAndRoles(Long groupId, List roleIds) { - return ""; - } - - @Override - public String softDeleteGroupRoleRelByMetalakeId(Long metalakeId) { - return "UPDATE " - + GROUP_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE group_id IN (SELECT group_id FROM " - + GROUP_TABLE_NAME - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0)" - + " AND deleted_at = 0"; - } - - @Override - public String softDeleteGroupRoleRelByRoleId(Long roleId) { - return "UPDATE " - + GROUP_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE role_id = #{roleId} AND deleted_at = 0"; - } - } - public static String batchInsertGroupRoleRel( @Param("groupRoleRels") List groupRoleRelPOS) { return getProvider().batchInsertGroupRoleRel(groupRoleRelPOS); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java index bfe9977a32d..67589459631 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java @@ -19,11 +19,10 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper.TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.MetalakeMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.MetalakePO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -52,70 +51,6 @@ static class MetalakeMetaMySQLProvider extends MetalakeMetaBaseSQLProvider {} static class MetalakeMetaH2Provider extends MetalakeMetaBaseSQLProvider {} - static class MetalakeMetaPostgreSQLProvider extends MetalakeMetaBaseSQLProvider { - - @Override - public String softDeleteMetalakeMetaByMetalakeId(Long metalakeId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertMetalakeMetaOnDuplicateKeyUpdate(MetalakePO metalakePO) { - return "INSERT INTO " - + TABLE_NAME - + "(metalake_id, metalake_name, metalake_comment, properties, audit_info," - + " schema_version, current_version, last_version, deleted_at)" - + " VALUES(" - + " #{metalakeMeta.metalakeId}," - + " #{metalakeMeta.metalakeName}," - + " #{metalakeMeta.metalakeComment}," - + " #{metalakeMeta.properties}," - + " #{metalakeMeta.auditInfo}," - + " #{metalakeMeta.schemaVersion}," - + " #{metalakeMeta.currentVersion}," - + " #{metalakeMeta.lastVersion}," - + " #{metalakeMeta.deletedAt}" - + " )" - + " ON CONFLICT(metalake_id) DO UPDATE SET" - + " metalake_name = #{metalakeMeta.metalakeName}," - + " metalake_comment = #{metalakeMeta.metalakeComment}," - + " properties = #{metalakeMeta.properties}," - + " audit_info = #{metalakeMeta.auditInfo}," - + " schema_version = #{metalakeMeta.schemaVersion}," - + " current_version = #{metalakeMeta.currentVersion}," - + " last_version = #{metalakeMeta.lastVersion}," - + " deleted_at = #{metalakeMeta.deletedAt}"; - } - - public String updateMetalakeMeta( - @Param("newMetalakeMeta") MetalakePO newMetalakePO, - @Param("oldMetalakeMeta") MetalakePO oldMetalakePO) { - return "UPDATE " - + TABLE_NAME - + " SET metalake_name = #{newMetalakeMeta.metalakeName}," - + " metalake_comment = #{newMetalakeMeta.metalakeComment}," - + " properties = #{newMetalakeMeta.properties}," - + " audit_info = #{newMetalakeMeta.auditInfo}," - + " schema_version = #{newMetalakeMeta.schemaVersion}," - + " current_version = #{newMetalakeMeta.currentVersion}," - + " last_version = #{newMetalakeMeta.lastVersion}" - + " WHERE metalake_id = #{oldMetalakeMeta.metalakeId}" - + " AND metalake_name = #{oldMetalakeMeta.metalakeName}" - + " AND (metalake_comment = #{oldMetalakeMeta.metalakeComment} " - + " OR (CAST(metalake_comment AS VARCHAR) IS NULL AND " - + " CAST(#{oldMetalakeMeta.metalakeComment} AS VARCHAR) IS NULL))" - + " AND properties = #{oldMetalakeMeta.properties}" - + " AND audit_info = #{oldMetalakeMeta.auditInfo}" - + " AND schema_version = #{oldMetalakeMeta.schemaVersion}" - + " AND current_version = #{oldMetalakeMeta.currentVersion}" - + " AND last_version = #{oldMetalakeMeta.lastVersion}" - + " AND deleted_at = 0"; - } - } - public String listMetalakePOs() { return getProvider().listMetalakePOs(); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/OwnerMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/OwnerMetaSQLProviderFactory.java index 55e042db13a..8ddf53d5d50 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/OwnerMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/OwnerMetaSQLProviderFactory.java @@ -18,11 +18,10 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper.OWNER_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.OwnerMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.OwnerRelPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -51,95 +50,6 @@ static class OwnerMetaMySQLProvider extends OwnerMetaBaseSQLProvider {} static class OwnerMetaH2Provider extends OwnerMetaBaseSQLProvider {} - static class OwnerMetaPostgreSQLProvider extends OwnerMetaBaseSQLProvider { - - @Override - public String softDeleteOwnerRelByMetadataObjectIdAndType( - Long metadataObjectId, String metadataObjectType) { - return "UPDATE " - + OWNER_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metadata_object_id = #{metadataObjectId} AND metadata_object_type = #{metadataObjectType} AND deleted_at = 0"; - } - - @Override - public String softDeleteOwnerRelByOwnerIdAndType(Long ownerId, String ownerType) { - return "UPDATE " - + OWNER_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE owner_id = #{ownerId} AND owner_type = #{ownerType} AND deleted_at = 0"; - } - - @Override - public String softDeleteOwnerRelByMetalakeId(Long metalakeId) { - return "UPDATE " - + OWNER_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at =0"; - } - - @Override - public String softDeleteOwnerRelByCatalogId(Long catalogId) { - return "UPDATE " - + OWNER_TABLE_NAME - + " ot SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE EXISTS (" - + " SELECT ct.catalog_id FROM " - + CatalogMetaMapper.TABLE_NAME - + " ct WHERE ct.catalog_id = #{catalogId} AND ct.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "ct.catalog_id = ot.metadata_object_id AND ot.metadata_object_type = 'CATALOG'" - + " UNION " - + " SELECT st.catalog_id FROM " - + SchemaMetaMapper.TABLE_NAME - + " st WHERE st.catalog_id = #{catalogId} AND st.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "st.schema_id = ot.metadata_object_id AND ot.metadata_object_type = 'SCHEMA'" - + " UNION " - + " SELECT tt.catalog_id FROM " - + TopicMetaMapper.TABLE_NAME - + " tt WHERE tt.catalog_id = #{catalogId} AND tt.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "tt.topic_id = ot.metadata_object_id AND ot.metadata_object_type = 'TOPIC'" - + " UNION " - + " SELECT tat.catalog_id FROM " - + TableMetaMapper.TABLE_NAME - + " tat WHERE tat.catalog_id = #{catalogId} AND tat.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "tat.table_id = ot.metadata_object_id AND ot.metadata_object_type = 'TABLE'" - + " UNION " - + " SELECT ft.catalog_id FROM " - + FilesetMetaMapper.META_TABLE_NAME - + " ft WHERE ft.catalog_id = #{catalogId} AND ft.deleted_at = 0 AND ot.deleted_at = 0 AND" - + " ft.fileset_id = ot.metadata_object_id AND ot.metadata_object_type = 'FILESET'" - + ")"; - } - - @Override - public String sotDeleteOwnerRelBySchemaId(Long schemaId) { - return "UPDATE " - + OWNER_TABLE_NAME - + " ot SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE EXISTS (" - + " SELECT st.schema_id FROM " - + SchemaMetaMapper.TABLE_NAME - + " st WHERE st.schema_id = #{schemaId} AND st.deleted_at = 0 AND ot.deleted_at = 0 " - + "AND st.schema_id = ot.metadata_object_id AND ot.metadata_object_type = 'SCHEMA'" - + " UNION " - + " SELECT tt.schema_id FROM " - + TopicMetaMapper.TABLE_NAME - + " tt WHERE tt.schema_id = #{schemaId} AND tt.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "tt.topic_id = ot.metadata_object_id AND ot.metadata_object_type = 'TOPIC'" - + " UNION " - + " SELECT tat.schema_id FROM " - + TableMetaMapper.TABLE_NAME - + " tat WHERE tat.schema_id = #{schemaId} AND tat.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "tat.table_id = ot.metadata_object_id AND ot.metadata_object_type = 'TABLE'" - + " UNION " - + " SELECT ft.schema_id FROM " - + FilesetMetaMapper.META_TABLE_NAME - + " ft WHERE ft.schema_id = #{schemaId} AND ft.deleted_at = 0 AND ot.deleted_at = 0 AND " - + "ft.fileset_id = ot.metadata_object_id AND ot.metadata_object_type = 'FILESET'" - + ")"; - } - } - public static String selectUserOwnerMetaByMetadataObjectIdAndType( @Param("metadataObjectId") Long metadataObjectId, @Param("metadataObjectType") String metadataObjectType) { diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/RoleMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/RoleMetaSQLProviderFactory.java index e898c4575c1..41599386003 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/RoleMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/RoleMetaSQLProviderFactory.java @@ -18,11 +18,10 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.RoleMetaMapper.ROLE_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.RoleMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.RolePO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -50,51 +49,6 @@ static class RoleMetaMySQLProvider extends RoleMetaBaseSQLProvider {} static class RoleMetaH2Provider extends RoleMetaBaseSQLProvider {} - static class RoleMetaPostgreSQLProvider extends RoleMetaBaseSQLProvider { - - @Override - public String softDeleteRoleMetaByRoleId(Long roleId) { - return "UPDATE " - + ROLE_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE role_id = #{roleId} AND deleted_at = 0"; - } - - @Override - public String softDeleteRoleMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + ROLE_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertRoleMetaOnDuplicateKeyUpdate(RolePO rolePO) { - return "INSERT INTO " - + ROLE_TABLE_NAME - + "(role_id, role_name," - + " metalake_id, properties," - + " audit_info, current_version, last_version, deleted_at)" - + " VALUES(" - + " #{roleMeta.roleId}," - + " #{roleMeta.roleName}," - + " #{roleMeta.metalakeId}," - + " #{roleMeta.properties}," - + " #{roleMeta.auditInfo}," - + " #{roleMeta.currentVersion}," - + " #{roleMeta.lastVersion}," - + " #{roleMeta.deletedAt}" - + " ) ON CONFLICT (role_id) DO UPDATE SET" - + " role_name = #{roleMeta.roleName}," - + " metalake_id = #{roleMeta.metalakeId}," - + " properties = #{roleMeta.properties}," - + " audit_info = #{roleMeta.auditInfo}," - + " current_version = #{roleMeta.currentVersion}," - + " last_version = #{roleMeta.lastVersion}," - + " deleted_at = #{roleMeta.deletedAt}"; - } - } - public static String selectRoleMetaByMetalakeIdAndName( @Param("metalakeId") Long metalakeId, @Param("roleName") String roleName) { return getProvider().selectRoleMetaByMetalakeIdAndName(metalakeId, roleName); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java index 1ffb1ce9adc..87f636e61d8 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java @@ -18,11 +18,10 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper.TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.SchemaMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.SchemaPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -50,64 +49,6 @@ static class SchemaMetaMySQLProvider extends SchemaMetaBaseSQLProvider {} static class SchemaMetaH2Provider extends SchemaMetaBaseSQLProvider {} - static class SchemaMetaPostgreSQLProvider extends SchemaMetaBaseSQLProvider { - - @Override - public String insertSchemaMetaOnDuplicateKeyUpdate(SchemaPO schemaPO) { - return "INSERT INTO " - + TABLE_NAME - + "(schema_id, schema_name, metalake_id," - + " catalog_id, schema_comment, properties, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{schemaMeta.schemaId}," - + " #{schemaMeta.schemaName}," - + " #{schemaMeta.metalakeId}," - + " #{schemaMeta.catalogId}," - + " #{schemaMeta.schemaComment}," - + " #{schemaMeta.properties}," - + " #{schemaMeta.auditInfo}," - + " #{schemaMeta.currentVersion}," - + " #{schemaMeta.lastVersion}," - + " #{schemaMeta.deletedAt}" - + " )" - + " ON CONFLICT(schema_id) DO UPDATE SET " - + " schema_name = #{schemaMeta.schemaName}," - + " metalake_id = #{schemaMeta.metalakeId}," - + " catalog_id = #{schemaMeta.catalogId}," - + " schema_comment = #{schemaMeta.schemaComment}," - + " properties = #{schemaMeta.properties}," - + " audit_info = #{schemaMeta.auditInfo}," - + " current_version = #{schemaMeta.currentVersion}," - + " last_version = #{schemaMeta.lastVersion}," - + " deleted_at = #{schemaMeta.deletedAt}"; - } - - @Override - public String softDeleteSchemaMetasBySchemaId(Long schemaId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; - } - - @Override - public String softDeleteSchemaMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String softDeleteSchemaMetasByCatalogId(Long catalogId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - } - public static String listSchemaPOsByCatalogId(@Param("catalogId") Long catalogId) { return getProvider().listSchemaPOsByCatalogId(catalogId); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SecurableObjectSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SecurableObjectSQLProviderFactory.java index 983bff90fb3..da4ddc730a0 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SecurableObjectSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SecurableObjectSQLProviderFactory.java @@ -18,13 +18,11 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper.ROLE_TABLE_NAME; -import static org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper.SECURABLE_OBJECT_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.SecurableObjectPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.SecurableObjectPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -53,28 +51,6 @@ static class SecurableObjectMySQLProvider extends SecurableObjectBaseSQLProvider static class SecurableObjectH2Provider extends SecurableObjectBaseSQLProvider {} - static class SecurableObjectPostgreSQLProvider extends SecurableObjectBaseSQLProvider { - - @Override - public String softDeleteSecurableObjectsByRoleId(Long roleId) { - return "UPDATE " - + SECURABLE_OBJECT_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE role_id = #{roleId} AND deleted_at = 0"; - } - - @Override - public String softDeleteRoleMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + SECURABLE_OBJECT_TABLE_NAME - + " ob SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE exists (SELECT * from " - + ROLE_TABLE_NAME - + " ro WHERE ro.metalake_id = #{metalakeId} AND ro.role_id = ob.role_id" - + " AND ro.deleted_at = 0) AND ob.deleted_at = 0"; - } - } - public static String batchInsertSecurableObjects( @Param("securableObjects") List securableObjectPOs) { return getProvider().batchInsertSecurableObjects(securableObjectPOs); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaSQLProviderFactory.java index 6c8895125be..619648c1f52 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaSQLProviderFactory.java @@ -18,11 +18,10 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.TableMetaMapper.TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.TableMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.TablePO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -51,70 +50,6 @@ static class TableMetaMySQLProvider extends TableMetaBaseSQLProvider {} static class TableMetaH2Provider extends TableMetaBaseSQLProvider {} - static class TableMetaPostgreSQLProvider extends TableMetaBaseSQLProvider { - - @Override - public String insertTableMetaOnDuplicateKeyUpdate(TablePO tablePO) { - return "INSERT INTO " - + TABLE_NAME - + "(table_id, table_name, metalake_id," - + " catalog_id, schema_id, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{tableMeta.tableId}," - + " #{tableMeta.tableName}," - + " #{tableMeta.metalakeId}," - + " #{tableMeta.catalogId}," - + " #{tableMeta.schemaId}," - + " #{tableMeta.auditInfo}," - + " #{tableMeta.currentVersion}," - + " #{tableMeta.lastVersion}," - + " #{tableMeta.deletedAt}" - + " )" - + " ON CONFLICT (table_id) DO UPDATE SET " - + " table_name = #{tableMeta.tableName}," - + " metalake_id = #{tableMeta.metalakeId}," - + " catalog_id = #{tableMeta.catalogId}," - + " schema_id = #{tableMeta.schemaId}," - + " audit_info = #{tableMeta.auditInfo}," - + " current_version = #{tableMeta.currentVersion}," - + " last_version = #{tableMeta.lastVersion}," - + " deleted_at = #{tableMeta.deletedAt}"; - } - - @Override - public String softDeleteTableMetasByTableId(Long tableId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE table_id = #{tableId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTableMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTableMetasByCatalogId(Long catalogId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTableMetasBySchemaId(Long schemaId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; - } - } - public static String listTablePOsBySchemaId(@Param("schemaId") Long schemaId) { return getProvider().listTablePOsBySchemaId(schemaId); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetaSQLProviderFactory.java index 30766199650..c9a018c5f2c 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetaSQLProviderFactory.java @@ -18,12 +18,11 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.TagMetaMapper.TAG_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.TagMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.TagPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -51,81 +50,6 @@ static class TagMetaMySQLProvider extends TagMetaBaseSQLProvider {} static class TagMetaH2Provider extends TagMetaBaseSQLProvider {} - static class TagMetaPostgreSQLProvider extends TagMetaBaseSQLProvider { - - @Override - public String softDeleteTagMetaByMetalakeAndTagName(String metalakeName, String tagName) { - return "UPDATE " - + TAG_TABLE_NAME - + " tm SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE tm.metalake_id IN (" - + " SELECT mm.metalake_id FROM " - + MetalakeMetaMapper.TABLE_NAME - + " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)" - + " AND tm.tag_name = #{tagName} AND tm.deleted_at = 0"; - } - - @Override - public String softDeleteTagMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + TAG_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertTagMetaOnDuplicateKeyUpdate(TagPO tagPO) { - return "INSERT INTO " - + TAG_TABLE_NAME - + "(tag_id, tag_name," - + " metalake_id, tag_comment, properties, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{tagMeta.tagId}," - + " #{tagMeta.tagName}," - + " #{tagMeta.metalakeId}," - + " #{tagMeta.comment}," - + " #{tagMeta.properties}," - + " #{tagMeta.auditInfo}," - + " #{tagMeta.currentVersion}," - + " #{tagMeta.lastVersion}," - + " #{tagMeta.deletedAt}" - + " )" - + " ON CONFLICT(tag_id) DO UPDATE SET" - + " tag_name = #{tagMeta.tagName}," - + " metalake_id = #{tagMeta.metalakeId}," - + " tag_comment = #{tagMeta.comment}," - + " properties = #{tagMeta.properties}," - + " audit_info = #{tagMeta.auditInfo}," - + " current_version = #{tagMeta.currentVersion}," - + " last_version = #{tagMeta.lastVersion}," - + " deleted_at = #{tagMeta.deletedAt}"; - } - - public String updateTagMeta( - @Param("newTagMeta") TagPO newTagPO, @Param("oldTagMeta") TagPO oldTagPO) { - return "UPDATE " - + TAG_TABLE_NAME - + " SET tag_name = #{newTagMeta.tagName}," - + " tag_comment = #{newTagMeta.comment}," - + " properties = #{newTagMeta.properties}," - + " audit_info = #{newTagMeta.auditInfo}," - + " current_version = #{newTagMeta.currentVersion}," - + " last_version = #{newTagMeta.lastVersion}," - + " deleted_at = #{newTagMeta.deletedAt}" - + " WHERE tag_id = #{oldTagMeta.tagId}" - + " AND metalake_id = #{oldTagMeta.metalakeId}" - + " AND tag_name = #{oldTagMeta.tagName}" - + " AND (tag_comment = #{oldTagMeta.comment} " - + " OR (CAST(tag_comment AS VARCHAR) IS NULL AND CAST(#{oldTagMeta.comment} AS VARCHAR) IS NULL))" - + " AND properties = #{oldTagMeta.properties}" - + " AND audit_info = #{oldTagMeta.auditInfo}" - + " AND current_version = #{oldTagMeta.currentVersion}" - + " AND last_version = #{oldTagMeta.lastVersion}" - + " AND deleted_at = 0"; - } - } - public static String listTagPOsByMetalake(@Param("metalakeName") String metalakeName) { return getProvider().listTagPOsByMetalake(metalakeName); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelSQLProviderFactory.java index a980faf1e51..af4522f9d95 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelSQLProviderFactory.java @@ -18,12 +18,11 @@ */ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper.TAG_METADATA_OBJECT_RELATION_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.TagMetadataObjectRelPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.TagMetadataObjectRelPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -52,68 +51,6 @@ static class TagMetadataObjectRelMySQLProvider extends TagMetadataObjectRelBaseS static class TagMetadataObjectRelH2Provider extends TagMetadataObjectRelBaseSQLProvider {} - static class TagMetadataObjectRelPostgreSQLProvider extends TagMetadataObjectRelBaseSQLProvider { - - @Override - public String softDeleteTagMetadataObjectRelsByMetalakeAndTagName( - String metalakeName, String tagName) { - return "UPDATE " - + TAG_METADATA_OBJECT_RELATION_TABLE_NAME - + " te SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE te.tag_id IN (SELECT tm.tag_id FROM " - + TagMetaMapper.TAG_TABLE_NAME - + " tm WHERE tm.metalake_id IN (SELECT mm.metalake_id FROM " - + MetalakeMetaMapper.TABLE_NAME - + " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)" - + " AND tm.deleted_at = 0) AND te.deleted_at = 0"; - } - - @Override - public String softDeleteTagMetadataObjectRelsByMetalakeId(Long metalakeId) { - return "UPDATE " - + TAG_METADATA_OBJECT_RELATION_TABLE_NAME - + " te SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE EXISTS (SELECT * FROM " - + TagMetaMapper.TAG_TABLE_NAME - + " tm WHERE tm.metalake_id = #{metalakeId} AND tm.tag_id = te.tag_id" - + " AND tm.deleted_at = 0) AND te.deleted_at = 0"; - } - - @Override - public String batchDeleteTagMetadataObjectRelsByTagIdsAndMetadataObject( - Long metadataObjectId, String metadataObjectType, List tagIds) { - return ""; - } - - @Override - public String listTagMetadataObjectRelsByMetalakeAndTagName( - String metalakeName, String tagName) { - return "SELECT te.tag_id as tagId, te.metadata_object_id as metadataObjectId," - + " te.metadata_object_type as metadataObjectType, te.audit_info as auditInfo," - + " te.current_version as currentVersion, te.last_version as lastVersion," - + " te.deleted_at as deletedAt" - + " FROM " - + TAG_METADATA_OBJECT_RELATION_TABLE_NAME - + " te JOIN " - + TagMetaMapper.TAG_TABLE_NAME - + " tm ON te.tag_id = tm.tag_id JOIN " - + MetalakeMetaMapper.TABLE_NAME - + " mm ON tm.metalake_id = mm.metalake_id" - + " WHERE mm.metalake_name = #{metalakeName} AND tm.tag_name = #{tagName}" - + " AND te.deleted_at = 0 AND tm.deleted_at = 0 AND mm.deleted_at = 0"; - } - } - public static String listTagPOsByMetadataObjectIdAndType( @Param("metadataObjectId") Long metadataObjectId, @Param("metadataObjectType") String metadataObjectType) { diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaSQLProviderFactory.java index ed078b8b5d6..c1c6e2e237d 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TopicMetaSQLProviderFactory.java @@ -19,11 +19,10 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.TopicMetaMapper.TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.TopicMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.TopicPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -52,74 +51,6 @@ static class TopicMetaMySQLProvider extends TopicMetaBaseSQLProvider {} static class TopicMetaH2Provider extends TopicMetaBaseSQLProvider {} - static class TopicMetaPostgreSQLProvider extends TopicMetaBaseSQLProvider { - - @Override - public String softDeleteTopicMetasByTopicId(Long topicId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE topic_id = #{topicId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTopicMetasByCatalogId(Long catalogId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTopicMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String softDeleteTopicMetasBySchemaId(Long schemaId) { - return "UPDATE " - + TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; - } - - @Override - public String insertTopicMetaOnDuplicateKeyUpdate(TopicPO topicPO) { - return "INSERT INTO " - + TABLE_NAME - + "(topic_id, topic_name, metalake_id, catalog_id, schema_id," - + " comment, properties, audit_info, current_version, last_version," - + " deleted_at)" - + " VALUES(" - + " #{topicMeta.topicId}," - + " #{topicMeta.topicName}," - + " #{topicMeta.metalakeId}," - + " #{topicMeta.catalogId}," - + " #{topicMeta.schemaId}," - + " #{topicMeta.comment}," - + " #{topicMeta.properties}," - + " #{topicMeta.auditInfo}," - + " #{topicMeta.currentVersion}," - + " #{topicMeta.lastVersion}," - + " #{topicMeta.deletedAt}" - + " )" - + " ON CONFLICT (topic_id) DO UPDATE SET" - + " topic_name = #{topicMeta.topicName}," - + " metalake_id = #{topicMeta.metalakeId}," - + " catalog_id = #{topicMeta.catalogId}," - + " schema_id = #{topicMeta.schemaId}," - + " comment = #{topicMeta.comment}," - + " properties = #{topicMeta.properties}," - + " audit_info = #{topicMeta.auditInfo}," - + " current_version = #{topicMeta.currentVersion}," - + " last_version = #{topicMeta.lastVersion}," - + " deleted_at = #{topicMeta.deletedAt}"; - } - } - public static String insertTopicMeta(@Param("topicMeta") TopicPO topicPO) { return getProvider().insertTopicMeta(topicPO); } diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaSQLProviderFactory.java index 1eaed8d9361..2c322db86d6 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaSQLProviderFactory.java @@ -19,11 +19,10 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.UserMetaPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.UserPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -52,50 +51,6 @@ static class UserMetaMySQLProvider extends UserMetaBaseSQLProvider {} static class UserMetaH2Provider extends UserMetaBaseSQLProvider {} - static class UserMetaPostgreSQLProvider extends UserMetaBaseSQLProvider { - - @Override - public String softDeleteUserMetaByUserId(Long userId) { - return "UPDATE " - + USER_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE user_id = #{userId} AND deleted_at = 0"; - } - - @Override - public String softDeleteUserMetasByMetalakeId(Long metalakeId) { - return "UPDATE " - + USER_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; - } - - @Override - public String insertUserMetaOnDuplicateKeyUpdate(UserPO userPO) { - return "INSERT INTO " - + USER_TABLE_NAME - + "(user_id, user_name," - + "metalake_id, audit_info," - + " current_version, last_version, deleted_at)" - + " VALUES(" - + " #{userMeta.userId}," - + " #{userMeta.userName}," - + " #{userMeta.metalakeId}," - + " #{userMeta.auditInfo}," - + " #{userMeta.currentVersion}," - + " #{userMeta.lastVersion}," - + " #{userMeta.deletedAt}" - + " )" - + " ON CONFLICT(user_id) DO UPDATE SET" - + " user_name = #{userMeta.userName}," - + " metalake_id = #{userMeta.metalakeId}," - + " audit_info = #{userMeta.auditInfo}," - + " current_version = #{userMeta.currentVersion}," - + " last_version = #{userMeta.lastVersion}," - + " deleted_at = #{userMeta.deletedAt}"; - } - } - public static String selectUserIdByMetalakeIdAndName( @Param("metalakeId") Long metalakeId, @Param("userName") String userName) { return getProvider().selectUserIdByMetalakeIdAndName(metalakeId, userName); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserRoleRelSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserRoleRelSQLProviderFactory.java index 8e041b7a3e3..f98f509f8f2 100644 --- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserRoleRelSQLProviderFactory.java +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserRoleRelSQLProviderFactory.java @@ -19,13 +19,11 @@ package org.apache.gravitino.storage.relational.mapper; -import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_ROLE_RELATION_TABLE_NAME; -import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_TABLE_NAME; - import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.Map; import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType; +import org.apache.gravitino.storage.relational.mapper.postgresql.UserRoleRelPostgreSQLProvider; import org.apache.gravitino.storage.relational.po.UserRoleRelPO; import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper; import org.apache.ibatis.annotations.Param; @@ -54,78 +52,6 @@ static class UserRoleRelMySQLProvider extends UserRoleRelBaseSQLProvider {} static class UserRoleRelH2Provider extends UserRoleRelBaseSQLProvider {} - static class UserRoleRelPostgreSQLProvider extends UserRoleRelBaseSQLProvider { - - @Override - public String softDeleteUserRoleRelByUserId(Long userId) { - return "UPDATE " - + USER_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE user_id = #{userId} AND deleted_at = 0"; - } - - @Override - public String softDeleteUserRoleRelByUserAndRoles(Long userId, List roleIds) { - return ""; - } - - @Override - public String softDeleteUserRoleRelByMetalakeId(Long metalakeId) { - return "UPDATE " - + USER_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE user_id IN (SELECT user_id FROM " - + USER_TABLE_NAME - + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0)" - + " AND deleted_at = 0"; - } - - @Override - public String softDeleteUserRoleRelByRoleId(Long roleId) { - return "UPDATE " - + USER_ROLE_RELATION_TABLE_NAME - + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " - + " WHERE role_id = #{roleId} AND deleted_at = 0"; - } - - @Override - public String batchInsertUserRoleRelOnDuplicateKeyUpdate(List userRoleRelPOs) { - return ""; - } - } - public static String batchInsertUserRoleRel( @Param("userRoleRels") List userRoleRelPOs) { return getProvider().batchInsertUserRoleRel(userRoleRelPOs); diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/CatalogMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/CatalogMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..df61ce5b4e8 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/CatalogMetaPostgreSQLProvider.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper.TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.CatalogMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.CatalogPO; +import org.apache.ibatis.annotations.Param; + +public class CatalogMetaPostgreSQLProvider extends CatalogMetaBaseSQLProvider { + @Override + public String softDeleteCatalogMetasByCatalogId(Long catalogId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } + + @Override + public String softDeleteCatalogMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertCatalogMetaOnDuplicateKeyUpdate(CatalogPO catalogPO) { + return "INSERT INTO " + + TABLE_NAME + + "(catalog_id, catalog_name, metalake_id," + + " type, provider, catalog_comment, properties, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{catalogMeta.catalogId}," + + " #{catalogMeta.catalogName}," + + " #{catalogMeta.metalakeId}," + + " #{catalogMeta.type}," + + " #{catalogMeta.provider}," + + " #{catalogMeta.catalogComment}," + + " #{catalogMeta.properties}," + + " #{catalogMeta.auditInfo}," + + " #{catalogMeta.currentVersion}," + + " #{catalogMeta.lastVersion}," + + " #{catalogMeta.deletedAt}" + + " )" + + " ON CONFLICT(catalog_id) DO UPDATE SET" + + " catalog_name = #{catalogMeta.catalogName}," + + " metalake_id = #{catalogMeta.metalakeId}," + + " type = #{catalogMeta.type}," + + " provider = #{catalogMeta.provider}," + + " catalog_comment = #{catalogMeta.catalogComment}," + + " properties = #{catalogMeta.properties}," + + " audit_info = #{catalogMeta.auditInfo}," + + " current_version = #{catalogMeta.currentVersion}," + + " last_version = #{catalogMeta.lastVersion}," + + " deleted_at = #{catalogMeta.deletedAt}"; + } + + public String updateCatalogMeta( + @Param("newCatalogMeta") CatalogPO newCatalogPO, + @Param("oldCatalogMeta") CatalogPO oldCatalogPO) { + return "UPDATE " + + TABLE_NAME + + " SET catalog_name = #{newCatalogMeta.catalogName}," + + " metalake_id = #{newCatalogMeta.metalakeId}," + + " type = #{newCatalogMeta.type}," + + " provider = #{newCatalogMeta.provider}," + + " catalog_comment = #{newCatalogMeta.catalogComment}," + + " properties = #{newCatalogMeta.properties}," + + " audit_info = #{newCatalogMeta.auditInfo}," + + " current_version = #{newCatalogMeta.currentVersion}," + + " last_version = #{newCatalogMeta.lastVersion}," + + " deleted_at = #{newCatalogMeta.deletedAt}" + + " WHERE catalog_id = #{oldCatalogMeta.catalogId}" + + " AND catalog_name = #{oldCatalogMeta.catalogName}" + + " AND metalake_id = #{oldCatalogMeta.metalakeId}" + + " AND type = #{oldCatalogMeta.type}" + + " AND provider = #{oldCatalogMeta.provider}" + + " AND (catalog_comment = #{oldCatalogMeta.catalogComment} " + + " OR (CAST(catalog_comment AS VARCHAR) IS NULL AND " + + " CAST(#{oldCatalogMeta.catalogComment} AS VARCHAR) IS NULL))" + + " AND properties = #{oldCatalogMeta.properties}" + + " AND audit_info = #{oldCatalogMeta.auditInfo}" + + " AND current_version = #{oldCatalogMeta.currentVersion}" + + " AND last_version = #{oldCatalogMeta.lastVersion}" + + " AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..5fbc0e6fe4a --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetMetaPostgreSQLProvider.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper.META_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.FilesetMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.FilesetPO; + +public class FilesetMetaPostgreSQLProvider extends FilesetMetaBaseSQLProvider { + @Override + public String softDeleteFilesetMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + META_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetMetasByCatalogId(Long catalogId) { + return "UPDATE " + + META_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetMetasBySchemaId(Long schemaId) { + return "UPDATE " + + META_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetMetasByFilesetId(Long filesetId) { + return "UPDATE " + + META_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE fileset_id = #{filesetId} AND deleted_at = 0"; + } + + @Override + public String insertFilesetMetaOnDuplicateKeyUpdate(FilesetPO filesetPO) { + return "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 CONFLICT(fileset_id) DO UPDATE SET" + + " 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}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetVersionPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetVersionPostgreSQLProvider.java new file mode 100644 index 00000000000..34dc1cfaa10 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/FilesetVersionPostgreSQLProvider.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.FilesetVersionMapper.VERSION_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.FilesetVersionBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.FilesetVersionPO; + +public class FilesetVersionPostgreSQLProvider extends FilesetVersionBaseSQLProvider { + @Override + public String softDeleteFilesetVersionsByMetalakeId(Long metalakeId) { + return "UPDATE " + + VERSION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetVersionsByCatalogId(Long catalogId) { + return "UPDATE " + + VERSION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetVersionsBySchemaId(Long schemaId) { + return "UPDATE " + + VERSION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetVersionsByFilesetId(Long filesetId) { + return "UPDATE " + + VERSION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE fileset_id = #{filesetId} AND deleted_at = 0"; + } + + @Override + public String softDeleteFilesetVersionsByRetentionLine( + Long filesetId, long versionRetentionLine, int limit) { + return "UPDATE " + + VERSION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE fileset_id = #{filesetId} AND version <= #{versionRetentionLine} AND deleted_at = 0 LIMIT #{limit}"; + } + + @Override + public String insertFilesetVersionOnDuplicateKeyUpdate(FilesetVersionPO filesetVersionPO) { + return "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 CONFLICT(fileset_id, version, deleted_at) DO UPDATE SET" + + " 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}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..b37c57528d6 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupMetaPostgreSQLProvider.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.GroupMetaMapper.GROUP_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.GroupMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.GroupPO; + +public class GroupMetaPostgreSQLProvider extends GroupMetaBaseSQLProvider { + @Override + public String softDeleteGroupMetaByGroupId(Long groupId) { + return "UPDATE " + + GROUP_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE group_id = #{groupId} AND deleted_at = 0"; + } + + @Override + public String softDeleteGroupMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + GROUP_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertGroupMetaOnDuplicateKeyUpdate(GroupPO groupPO) { + return "INSERT INTO " + + GROUP_TABLE_NAME + + "(group_id, group_name," + + "metalake_id, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{groupMeta.groupId}," + + " #{groupMeta.groupName}," + + " #{groupMeta.metalakeId}," + + " #{groupMeta.auditInfo}," + + " #{groupMeta.currentVersion}," + + " #{groupMeta.lastVersion}," + + " #{groupMeta.deletedAt}" + + " )" + + " ON CONFLICT(group_id) DO UPDATE SET" + + " group_name = #{groupMeta.groupName}," + + " metalake_id = #{groupMeta.metalakeId}," + + " audit_info = #{groupMeta.auditInfo}," + + " current_version = #{groupMeta.currentVersion}," + + " last_version = #{groupMeta.lastVersion}," + + " deleted_at = #{groupMeta.deletedAt}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupRoleRelPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupRoleRelPostgreSQLProvider.java new file mode 100644 index 00000000000..b696d8d54e5 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/GroupRoleRelPostgreSQLProvider.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.GroupRoleRelMapper.GROUP_ROLE_RELATION_TABLE_NAME; +import static org.apache.gravitino.storage.relational.mapper.GroupRoleRelMapper.GROUP_TABLE_NAME; + +import java.util.List; +import org.apache.gravitino.storage.relational.mapper.GroupRoleRelBaseSQLProvider; + +public class GroupRoleRelPostgreSQLProvider extends GroupRoleRelBaseSQLProvider { + @Override + public String softDeleteGroupRoleRelByGroupId(Long groupId) { + return "UPDATE " + + GROUP_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE group_id = #{groupId} AND deleted_at = 0"; + } + + @Override + public String softDeleteGroupRoleRelByGroupAndRoles(Long groupId, List roleIds) { + return ""; + } + + @Override + public String softDeleteGroupRoleRelByMetalakeId(Long metalakeId) { + return "UPDATE " + + GROUP_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE group_id IN (SELECT group_id FROM " + + GROUP_TABLE_NAME + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0)" + + " AND deleted_at = 0"; + } + + @Override + public String softDeleteGroupRoleRelByRoleId(Long roleId) { + return "UPDATE " + + GROUP_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE role_id = #{roleId} AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/MetalakeMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/MetalakeMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..3e6c479308f --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/MetalakeMetaPostgreSQLProvider.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper.TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.MetalakeMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.MetalakePO; +import org.apache.ibatis.annotations.Param; + +public class MetalakeMetaPostgreSQLProvider extends MetalakeMetaBaseSQLProvider { + @Override + public String softDeleteMetalakeMetaByMetalakeId(Long metalakeId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertMetalakeMetaOnDuplicateKeyUpdate(MetalakePO metalakePO) { + return "INSERT INTO " + + TABLE_NAME + + "(metalake_id, metalake_name, metalake_comment, properties, audit_info," + + " schema_version, current_version, last_version, deleted_at)" + + " VALUES(" + + " #{metalakeMeta.metalakeId}," + + " #{metalakeMeta.metalakeName}," + + " #{metalakeMeta.metalakeComment}," + + " #{metalakeMeta.properties}," + + " #{metalakeMeta.auditInfo}," + + " #{metalakeMeta.schemaVersion}," + + " #{metalakeMeta.currentVersion}," + + " #{metalakeMeta.lastVersion}," + + " #{metalakeMeta.deletedAt}" + + " )" + + " ON CONFLICT(metalake_id) DO UPDATE SET" + + " metalake_name = #{metalakeMeta.metalakeName}," + + " metalake_comment = #{metalakeMeta.metalakeComment}," + + " properties = #{metalakeMeta.properties}," + + " audit_info = #{metalakeMeta.auditInfo}," + + " schema_version = #{metalakeMeta.schemaVersion}," + + " current_version = #{metalakeMeta.currentVersion}," + + " last_version = #{metalakeMeta.lastVersion}," + + " deleted_at = #{metalakeMeta.deletedAt}"; + } + + public String updateMetalakeMeta( + @Param("newMetalakeMeta") MetalakePO newMetalakePO, + @Param("oldMetalakeMeta") MetalakePO oldMetalakePO) { + return "UPDATE " + + TABLE_NAME + + " SET metalake_name = #{newMetalakeMeta.metalakeName}," + + " metalake_comment = #{newMetalakeMeta.metalakeComment}," + + " properties = #{newMetalakeMeta.properties}," + + " audit_info = #{newMetalakeMeta.auditInfo}," + + " schema_version = #{newMetalakeMeta.schemaVersion}," + + " current_version = #{newMetalakeMeta.currentVersion}," + + " last_version = #{newMetalakeMeta.lastVersion}" + + " WHERE metalake_id = #{oldMetalakeMeta.metalakeId}" + + " AND metalake_name = #{oldMetalakeMeta.metalakeName}" + + " AND (metalake_comment = #{oldMetalakeMeta.metalakeComment} " + + " OR (CAST(metalake_comment AS VARCHAR) IS NULL AND " + + " CAST(#{oldMetalakeMeta.metalakeComment} AS VARCHAR) IS NULL))" + + " AND properties = #{oldMetalakeMeta.properties}" + + " AND audit_info = #{oldMetalakeMeta.auditInfo}" + + " AND schema_version = #{oldMetalakeMeta.schemaVersion}" + + " AND current_version = #{oldMetalakeMeta.currentVersion}" + + " AND last_version = #{oldMetalakeMeta.lastVersion}" + + " AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/OwnerMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/OwnerMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..2d7104658a0 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/OwnerMetaPostgreSQLProvider.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper.OWNER_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper; +import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper; +import org.apache.gravitino.storage.relational.mapper.OwnerMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TableMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper; + +public class OwnerMetaPostgreSQLProvider extends OwnerMetaBaseSQLProvider { + @Override + public String softDeleteOwnerRelByMetadataObjectIdAndType( + Long metadataObjectId, String metadataObjectType) { + return "UPDATE " + + OWNER_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metadata_object_id = #{metadataObjectId} AND metadata_object_type = #{metadataObjectType} AND deleted_at = 0"; + } + + @Override + public String softDeleteOwnerRelByOwnerIdAndType(Long ownerId, String ownerType) { + return "UPDATE " + + OWNER_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE owner_id = #{ownerId} AND owner_type = #{ownerType} AND deleted_at = 0"; + } + + @Override + public String softDeleteOwnerRelByMetalakeId(Long metalakeId) { + return "UPDATE " + + OWNER_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at =0"; + } + + @Override + public String softDeleteOwnerRelByCatalogId(Long catalogId) { + return "UPDATE " + + OWNER_TABLE_NAME + + " ot SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE EXISTS (" + + " SELECT ct.catalog_id FROM " + + CatalogMetaMapper.TABLE_NAME + + " ct WHERE ct.catalog_id = #{catalogId} AND ct.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "ct.catalog_id = ot.metadata_object_id AND ot.metadata_object_type = 'CATALOG'" + + " UNION " + + " SELECT st.catalog_id FROM " + + SchemaMetaMapper.TABLE_NAME + + " st WHERE st.catalog_id = #{catalogId} AND st.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "st.schema_id = ot.metadata_object_id AND ot.metadata_object_type = 'SCHEMA'" + + " UNION " + + " SELECT tt.catalog_id FROM " + + TopicMetaMapper.TABLE_NAME + + " tt WHERE tt.catalog_id = #{catalogId} AND tt.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "tt.topic_id = ot.metadata_object_id AND ot.metadata_object_type = 'TOPIC'" + + " UNION " + + " SELECT tat.catalog_id FROM " + + TableMetaMapper.TABLE_NAME + + " tat WHERE tat.catalog_id = #{catalogId} AND tat.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "tat.table_id = ot.metadata_object_id AND ot.metadata_object_type = 'TABLE'" + + " UNION " + + " SELECT ft.catalog_id FROM " + + FilesetMetaMapper.META_TABLE_NAME + + " ft WHERE ft.catalog_id = #{catalogId} AND ft.deleted_at = 0 AND ot.deleted_at = 0 AND" + + " ft.fileset_id = ot.metadata_object_id AND ot.metadata_object_type = 'FILESET'" + + ")"; + } + + @Override + public String sotDeleteOwnerRelBySchemaId(Long schemaId) { + return "UPDATE " + + OWNER_TABLE_NAME + + " ot SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE EXISTS (" + + " SELECT st.schema_id FROM " + + SchemaMetaMapper.TABLE_NAME + + " st WHERE st.schema_id = #{schemaId} AND st.deleted_at = 0 AND ot.deleted_at = 0 " + + "AND st.schema_id = ot.metadata_object_id AND ot.metadata_object_type = 'SCHEMA'" + + " UNION " + + " SELECT tt.schema_id FROM " + + TopicMetaMapper.TABLE_NAME + + " tt WHERE tt.schema_id = #{schemaId} AND tt.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "tt.topic_id = ot.metadata_object_id AND ot.metadata_object_type = 'TOPIC'" + + " UNION " + + " SELECT tat.schema_id FROM " + + TableMetaMapper.TABLE_NAME + + " tat WHERE tat.schema_id = #{schemaId} AND tat.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "tat.table_id = ot.metadata_object_id AND ot.metadata_object_type = 'TABLE'" + + " UNION " + + " SELECT ft.schema_id FROM " + + FilesetMetaMapper.META_TABLE_NAME + + " ft WHERE ft.schema_id = #{schemaId} AND ft.deleted_at = 0 AND ot.deleted_at = 0 AND " + + "ft.fileset_id = ot.metadata_object_id AND ot.metadata_object_type = 'FILESET'" + + ")"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/RoleMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/RoleMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..733c514cf33 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/RoleMetaPostgreSQLProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.RoleMetaMapper.ROLE_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.RoleMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.RolePO; + +public class RoleMetaPostgreSQLProvider extends RoleMetaBaseSQLProvider { + @Override + public String softDeleteRoleMetaByRoleId(Long roleId) { + return "UPDATE " + + ROLE_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE role_id = #{roleId} AND deleted_at = 0"; + } + + @Override + public String softDeleteRoleMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + ROLE_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertRoleMetaOnDuplicateKeyUpdate(RolePO rolePO) { + return "INSERT INTO " + + ROLE_TABLE_NAME + + "(role_id, role_name," + + " metalake_id, properties," + + " audit_info, current_version, last_version, deleted_at)" + + " VALUES(" + + " #{roleMeta.roleId}," + + " #{roleMeta.roleName}," + + " #{roleMeta.metalakeId}," + + " #{roleMeta.properties}," + + " #{roleMeta.auditInfo}," + + " #{roleMeta.currentVersion}," + + " #{roleMeta.lastVersion}," + + " #{roleMeta.deletedAt}" + + " ) ON CONFLICT (role_id) DO UPDATE SET" + + " role_name = #{roleMeta.roleName}," + + " metalake_id = #{roleMeta.metalakeId}," + + " properties = #{roleMeta.properties}," + + " audit_info = #{roleMeta.auditInfo}," + + " current_version = #{roleMeta.currentVersion}," + + " last_version = #{roleMeta.lastVersion}," + + " deleted_at = #{roleMeta.deletedAt}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SchemaMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SchemaMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..a51e0df88e0 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SchemaMetaPostgreSQLProvider.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper.TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.SchemaMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.SchemaPO; + +public class SchemaMetaPostgreSQLProvider extends SchemaMetaBaseSQLProvider { + @Override + public String insertSchemaMetaOnDuplicateKeyUpdate(SchemaPO schemaPO) { + return "INSERT INTO " + + TABLE_NAME + + "(schema_id, schema_name, metalake_id," + + " catalog_id, schema_comment, properties, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{schemaMeta.schemaId}," + + " #{schemaMeta.schemaName}," + + " #{schemaMeta.metalakeId}," + + " #{schemaMeta.catalogId}," + + " #{schemaMeta.schemaComment}," + + " #{schemaMeta.properties}," + + " #{schemaMeta.auditInfo}," + + " #{schemaMeta.currentVersion}," + + " #{schemaMeta.lastVersion}," + + " #{schemaMeta.deletedAt}" + + " )" + + " ON CONFLICT(schema_id) DO UPDATE SET " + + " schema_name = #{schemaMeta.schemaName}," + + " metalake_id = #{schemaMeta.metalakeId}," + + " catalog_id = #{schemaMeta.catalogId}," + + " schema_comment = #{schemaMeta.schemaComment}," + + " properties = #{schemaMeta.properties}," + + " audit_info = #{schemaMeta.auditInfo}," + + " current_version = #{schemaMeta.currentVersion}," + + " last_version = #{schemaMeta.lastVersion}," + + " deleted_at = #{schemaMeta.deletedAt}"; + } + + @Override + public String softDeleteSchemaMetasBySchemaId(Long schemaId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; + } + + @Override + public String softDeleteSchemaMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String softDeleteSchemaMetasByCatalogId(Long catalogId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SecurableObjectPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SecurableObjectPostgreSQLProvider.java new file mode 100644 index 00000000000..0a12df8132b --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/SecurableObjectPostgreSQLProvider.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper.ROLE_TABLE_NAME; +import static org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper.SECURABLE_OBJECT_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.SecurableObjectBaseSQLProvider; + +public class SecurableObjectPostgreSQLProvider extends SecurableObjectBaseSQLProvider { + @Override + public String softDeleteSecurableObjectsByRoleId(Long roleId) { + return "UPDATE " + + SECURABLE_OBJECT_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE role_id = #{roleId} AND deleted_at = 0"; + } + + @Override + public String softDeleteRoleMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + SECURABLE_OBJECT_TABLE_NAME + + " ob SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE exists (SELECT * from " + + ROLE_TABLE_NAME + + " ro WHERE ro.metalake_id = #{metalakeId} AND ro.role_id = ob.role_id" + + " AND ro.deleted_at = 0) AND ob.deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TableMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TableMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..a2d5df30987 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TableMetaPostgreSQLProvider.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.TableMetaMapper.TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.TableMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.TablePO; + +public class TableMetaPostgreSQLProvider extends TableMetaBaseSQLProvider { + @Override + public String insertTableMetaOnDuplicateKeyUpdate(TablePO tablePO) { + return "INSERT INTO " + + TABLE_NAME + + "(table_id, table_name, metalake_id," + + " catalog_id, schema_id, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{tableMeta.tableId}," + + " #{tableMeta.tableName}," + + " #{tableMeta.metalakeId}," + + " #{tableMeta.catalogId}," + + " #{tableMeta.schemaId}," + + " #{tableMeta.auditInfo}," + + " #{tableMeta.currentVersion}," + + " #{tableMeta.lastVersion}," + + " #{tableMeta.deletedAt}" + + " )" + + " ON CONFLICT (table_id) DO UPDATE SET " + + " table_name = #{tableMeta.tableName}," + + " metalake_id = #{tableMeta.metalakeId}," + + " catalog_id = #{tableMeta.catalogId}," + + " schema_id = #{tableMeta.schemaId}," + + " audit_info = #{tableMeta.auditInfo}," + + " current_version = #{tableMeta.currentVersion}," + + " last_version = #{tableMeta.lastVersion}," + + " deleted_at = #{tableMeta.deletedAt}"; + } + + @Override + public String softDeleteTableMetasByTableId(Long tableId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE table_id = #{tableId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTableMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTableMetasByCatalogId(Long catalogId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTableMetasBySchemaId(Long schemaId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..0194f95e837 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetaPostgreSQLProvider.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.TagMetaMapper.TAG_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TagMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.TagPO; +import org.apache.ibatis.annotations.Param; + +public class TagMetaPostgreSQLProvider extends TagMetaBaseSQLProvider { + @Override + public String softDeleteTagMetaByMetalakeAndTagName(String metalakeName, String tagName) { + return "UPDATE " + + TAG_TABLE_NAME + + " tm SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE tm.metalake_id IN (" + + " SELECT mm.metalake_id FROM " + + MetalakeMetaMapper.TABLE_NAME + + " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)" + + " AND tm.tag_name = #{tagName} AND tm.deleted_at = 0"; + } + + @Override + public String softDeleteTagMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + TAG_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertTagMetaOnDuplicateKeyUpdate(TagPO tagPO) { + return "INSERT INTO " + + TAG_TABLE_NAME + + "(tag_id, tag_name," + + " metalake_id, tag_comment, properties, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{tagMeta.tagId}," + + " #{tagMeta.tagName}," + + " #{tagMeta.metalakeId}," + + " #{tagMeta.comment}," + + " #{tagMeta.properties}," + + " #{tagMeta.auditInfo}," + + " #{tagMeta.currentVersion}," + + " #{tagMeta.lastVersion}," + + " #{tagMeta.deletedAt}" + + " )" + + " ON CONFLICT(tag_id) DO UPDATE SET" + + " tag_name = #{tagMeta.tagName}," + + " metalake_id = #{tagMeta.metalakeId}," + + " tag_comment = #{tagMeta.comment}," + + " properties = #{tagMeta.properties}," + + " audit_info = #{tagMeta.auditInfo}," + + " current_version = #{tagMeta.currentVersion}," + + " last_version = #{tagMeta.lastVersion}," + + " deleted_at = #{tagMeta.deletedAt}"; + } + + public String updateTagMeta( + @Param("newTagMeta") TagPO newTagPO, @Param("oldTagMeta") TagPO oldTagPO) { + return "UPDATE " + + TAG_TABLE_NAME + + " SET tag_name = #{newTagMeta.tagName}," + + " tag_comment = #{newTagMeta.comment}," + + " properties = #{newTagMeta.properties}," + + " audit_info = #{newTagMeta.auditInfo}," + + " current_version = #{newTagMeta.currentVersion}," + + " last_version = #{newTagMeta.lastVersion}," + + " deleted_at = #{newTagMeta.deletedAt}" + + " WHERE tag_id = #{oldTagMeta.tagId}" + + " AND metalake_id = #{oldTagMeta.metalakeId}" + + " AND tag_name = #{oldTagMeta.tagName}" + + " AND (tag_comment = #{oldTagMeta.comment} " + + " OR (CAST(tag_comment AS VARCHAR) IS NULL AND CAST(#{oldTagMeta.comment} AS VARCHAR) IS NULL))" + + " AND properties = #{oldTagMeta.properties}" + + " AND audit_info = #{oldTagMeta.auditInfo}" + + " AND current_version = #{oldTagMeta.currentVersion}" + + " AND last_version = #{oldTagMeta.lastVersion}" + + " AND deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetadataObjectRelPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetadataObjectRelPostgreSQLProvider.java new file mode 100644 index 00000000000..3310167e183 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TagMetadataObjectRelPostgreSQLProvider.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper.TAG_METADATA_OBJECT_RELATION_TABLE_NAME; + +import java.util.List; +import org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TagMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelBaseSQLProvider; + +public class TagMetadataObjectRelPostgreSQLProvider extends TagMetadataObjectRelBaseSQLProvider { + @Override + public String softDeleteTagMetadataObjectRelsByMetalakeAndTagName( + String metalakeName, String tagName) { + return "UPDATE " + + TAG_METADATA_OBJECT_RELATION_TABLE_NAME + + " te SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE te.tag_id IN (SELECT tm.tag_id FROM " + + TagMetaMapper.TAG_TABLE_NAME + + " tm WHERE tm.metalake_id IN (SELECT mm.metalake_id FROM " + + MetalakeMetaMapper.TABLE_NAME + + " mm WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0)" + + " AND tm.deleted_at = 0) AND te.deleted_at = 0"; + } + + @Override + public String softDeleteTagMetadataObjectRelsByMetalakeId(Long metalakeId) { + return "UPDATE " + + TAG_METADATA_OBJECT_RELATION_TABLE_NAME + + " te SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE EXISTS (SELECT * FROM " + + TagMetaMapper.TAG_TABLE_NAME + + " tm WHERE tm.metalake_id = #{metalakeId} AND tm.tag_id = te.tag_id" + + " AND tm.deleted_at = 0) AND te.deleted_at = 0"; + } + + @Override + public String batchDeleteTagMetadataObjectRelsByTagIdsAndMetadataObject( + Long metadataObjectId, String metadataObjectType, List tagIds) { + return ""; + } + + @Override + public String listTagMetadataObjectRelsByMetalakeAndTagName(String metalakeName, String tagName) { + return "SELECT te.tag_id as tagId, te.metadata_object_id as metadataObjectId," + + " te.metadata_object_type as metadataObjectType, te.audit_info as auditInfo," + + " te.current_version as currentVersion, te.last_version as lastVersion," + + " te.deleted_at as deletedAt" + + " FROM " + + TAG_METADATA_OBJECT_RELATION_TABLE_NAME + + " te JOIN " + + TagMetaMapper.TAG_TABLE_NAME + + " tm ON te.tag_id = tm.tag_id JOIN " + + MetalakeMetaMapper.TABLE_NAME + + " mm ON tm.metalake_id = mm.metalake_id" + + " WHERE mm.metalake_name = #{metalakeName} AND tm.tag_name = #{tagName}" + + " AND te.deleted_at = 0 AND tm.deleted_at = 0 AND mm.deleted_at = 0"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TopicMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TopicMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..b724259175b --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/TopicMetaPostgreSQLProvider.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.TopicMetaMapper.TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.TopicMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.TopicPO; + +public class TopicMetaPostgreSQLProvider extends TopicMetaBaseSQLProvider { + + @Override + public String softDeleteTopicMetasByTopicId(Long topicId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE topic_id = #{topicId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTopicMetasByCatalogId(Long catalogId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE catalog_id = #{catalogId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTopicMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)))" + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String softDeleteTopicMetasBySchemaId(Long schemaId) { + return "UPDATE " + + TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE schema_id = #{schemaId} AND deleted_at = 0"; + } + + @Override + public String insertTopicMetaOnDuplicateKeyUpdate(TopicPO topicPO) { + return "INSERT INTO " + + TABLE_NAME + + "(topic_id, topic_name, metalake_id, catalog_id, schema_id," + + " comment, properties, audit_info, current_version, last_version," + + " deleted_at)" + + " VALUES(" + + " #{topicMeta.topicId}," + + " #{topicMeta.topicName}," + + " #{topicMeta.metalakeId}," + + " #{topicMeta.catalogId}," + + " #{topicMeta.schemaId}," + + " #{topicMeta.comment}," + + " #{topicMeta.properties}," + + " #{topicMeta.auditInfo}," + + " #{topicMeta.currentVersion}," + + " #{topicMeta.lastVersion}," + + " #{topicMeta.deletedAt}" + + " )" + + " ON CONFLICT (topic_id) DO UPDATE SET" + + " topic_name = #{topicMeta.topicName}," + + " metalake_id = #{topicMeta.metalakeId}," + + " catalog_id = #{topicMeta.catalogId}," + + " schema_id = #{topicMeta.schemaId}," + + " comment = #{topicMeta.comment}," + + " properties = #{topicMeta.properties}," + + " audit_info = #{topicMeta.auditInfo}," + + " current_version = #{topicMeta.currentVersion}," + + " last_version = #{topicMeta.lastVersion}," + + " deleted_at = #{topicMeta.deletedAt}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserMetaPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserMetaPostgreSQLProvider.java new file mode 100644 index 00000000000..aa63ed40798 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserMetaPostgreSQLProvider.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_TABLE_NAME; + +import org.apache.gravitino.storage.relational.mapper.UserMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.UserPO; + +public class UserMetaPostgreSQLProvider extends UserMetaBaseSQLProvider { + @Override + public String softDeleteUserMetaByUserId(Long userId) { + return "UPDATE " + + USER_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE user_id = #{userId} AND deleted_at = 0"; + } + + @Override + public String softDeleteUserMetasByMetalakeId(Long metalakeId) { + return "UPDATE " + + USER_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0"; + } + + @Override + public String insertUserMetaOnDuplicateKeyUpdate(UserPO userPO) { + return "INSERT INTO " + + USER_TABLE_NAME + + "(user_id, user_name," + + "metalake_id, audit_info," + + " current_version, last_version, deleted_at)" + + " VALUES(" + + " #{userMeta.userId}," + + " #{userMeta.userName}," + + " #{userMeta.metalakeId}," + + " #{userMeta.auditInfo}," + + " #{userMeta.currentVersion}," + + " #{userMeta.lastVersion}," + + " #{userMeta.deletedAt}" + + " )" + + " ON CONFLICT(user_id) DO UPDATE SET" + + " user_name = #{userMeta.userName}," + + " metalake_id = #{userMeta.metalakeId}," + + " audit_info = #{userMeta.auditInfo}," + + " current_version = #{userMeta.currentVersion}," + + " last_version = #{userMeta.lastVersion}," + + " deleted_at = #{userMeta.deletedAt}"; + } +} diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserRoleRelPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserRoleRelPostgreSQLProvider.java new file mode 100644 index 00000000000..c59bb82795f --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/postgresql/UserRoleRelPostgreSQLProvider.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.storage.relational.mapper.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_ROLE_RELATION_TABLE_NAME; +import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_TABLE_NAME; + +import java.util.List; +import org.apache.gravitino.storage.relational.mapper.UserRoleRelBaseSQLProvider; +import org.apache.gravitino.storage.relational.po.UserRoleRelPO; + +public class UserRoleRelPostgreSQLProvider extends UserRoleRelBaseSQLProvider { + @Override + public String softDeleteUserRoleRelByUserId(Long userId) { + return "UPDATE " + + USER_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE user_id = #{userId} AND deleted_at = 0"; + } + + @Override + public String softDeleteUserRoleRelByUserAndRoles(Long userId, List roleIds) { + return ""; + } + + @Override + public String softDeleteUserRoleRelByMetalakeId(Long metalakeId) { + return "UPDATE " + + USER_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE user_id IN (SELECT user_id FROM " + + USER_TABLE_NAME + + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0)" + + " AND deleted_at = 0"; + } + + @Override + public String softDeleteUserRoleRelByRoleId(Long roleId) { + return "UPDATE " + + USER_ROLE_RELATION_TABLE_NAME + + " SET deleted_at = floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) " + + " WHERE role_id = #{roleId} AND deleted_at = 0"; + } + + @Override + public String batchInsertUserRoleRelOnDuplicateKeyUpdate(List userRoleRelPOs) { + return ""; + } +}