mchades commented on code in PR #7722: URL: https://github.com/apache/gravitino/pull/7722#discussion_r2250311802
########## core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/PolicyMetadataObjectRelPostgreSQLProvider.java: ########## @@ -0,0 +1,201 @@ +/* + * 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.provider.postgresql; + +import static org.apache.gravitino.storage.relational.mapper.PolicyMetadataObjectRelMapper.POLICY_METADATA_OBJECT_RELATION_TABLE_NAME; + +import java.util.List; +import org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper; +import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper; +import org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper; +import org.apache.gravitino.storage.relational.mapper.ModelMetaMapper; +import org.apache.gravitino.storage.relational.mapper.PolicyMetaMapper; +import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TableColumnMapper; +import org.apache.gravitino.storage.relational.mapper.TableMetaMapper; +import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper; +import org.apache.gravitino.storage.relational.mapper.provider.base.PolicyMetadataObjectRelBaseSQLProvider; +import org.apache.ibatis.annotations.Param; + +public class PolicyMetadataObjectRelPostgreSQLProvider + extends PolicyMetadataObjectRelBaseSQLProvider { + private static final String DELETED_AT_NOW_EXPRESSION = + " floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000))) "; + + @Override + public String softDeletePolicyMetadataObjectRelsByMetalakeAndPolicyName( + String metalakeName, String policyName) { + return "UPDATE " + + POLICY_METADATA_OBJECT_RELATION_TABLE_NAME + + " te SET deleted_at =" + + DELETED_AT_NOW_EXPRESSION + + " WHERE te.policy_id IN (SELECT tm.policy_id FROM " + + PolicyMetaMapper.POLICY_META_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.policy_name = #{policyName} AND tm.deleted_at = 0) AND te.deleted_at = 0"; + } + + @Override + public String softDeletePolicyMetadataObjectRelsByMetalakeId(Long metalakeId) { + return "UPDATE " + + POLICY_METADATA_OBJECT_RELATION_TABLE_NAME + + " te SET deleted_at =" + + DELETED_AT_NOW_EXPRESSION + + " WHERE te.policy_id IN (SELECT tm.policy_id FROM " + + PolicyMetaMapper.POLICY_META_TABLE_NAME + + " tm WHERE tm.metalake_id = #{metalakeId} AND tm.deleted_at = 0) AND te.deleted_at = 0"; + } + + @Override + public String softDeletePolicyMetadataObjectRelsByMetadataObject( + @Param("metadataObjectId") Long metadataObjectId, + @Param("metadataObjectType") String metadataObjectType) { + return "UPDATE " + + POLICY_METADATA_OBJECT_RELATION_TABLE_NAME + + " SET deleted_at =" + + DELETED_AT_NOW_EXPRESSION + + " WHERE metadata_object_id = #{metadataObjectId} AND deleted_at = 0" + + " AND metadata_object_type = #{metadataObjectType}"; + } + + @Override + public String softDeletePolicyMetadataObjectRelsByCatalogId(@Param("catalogId") Long catalogId) { + return "UPDATE " + + POLICY_METADATA_OBJECT_RELATION_TABLE_NAME + + " pe SET deleted_at =" + + DELETED_AT_NOW_EXPRESSION + + " FROM " + + POLICY_METADATA_OBJECT_RELATION_TABLE_NAME + + " pe_alias" + + " LEFT JOIN " + + CatalogMetaMapper.TABLE_NAME + + " ct ON pe_alias.metadata_object_id = ct.catalog_id AND pe_alias.metadata_object_type = 'CATALOG'" + + " LEFT JOIN " + + SchemaMetaMapper.TABLE_NAME + + " st ON pe_alias.metadata_object_id = st.schema_id AND pe_alias.metadata_object_type = 'SCHEMA'" + + " LEFT JOIN " + + TopicMetaMapper.TABLE_NAME + + " tt ON pe_alias.metadata_object_id = tt.topic_id AND pe_alias.metadata_object_type = 'TOPIC'" + + " LEFT JOIN " + + TableMetaMapper.TABLE_NAME + + " tat ON pe_alias.metadata_object_id = tat.table_id AND pe_alias.metadata_object_type = 'TABLE'" + + " LEFT JOIN " + + FilesetMetaMapper.META_TABLE_NAME + + " ft ON pe_alias.metadata_object_id = ft.fileset_id AND pe_alias.metadata_object_type = 'FILESET'" + + " LEFT JOIN " Review Comment: Yeah, we may need to perform some pressure tests for Gravitino in a stable version. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
