From 161d76328da37e2a5c3a9cf92b64bda3891b5f21 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:00:13 +0800 Subject: [PATCH] branch-2.1: [fix](iceberg)Delete the data files when deleting the table #43441 (#44138) Cherry-picked from #43441 Co-authored-by: wuwenchi --- .../iceberg/IcebergMetadataOps.java | 2 +- .../iceberg/iceberg_drop_rest_table.out | 9 ++ .../iceberg/iceberg_drop_rest_table.groovy | 90 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 regression-test/data/external_table_p0/iceberg/iceberg_drop_rest_table.out create mode 100644 regression-test/suites/external_table_p0/iceberg/iceberg_drop_rest_table.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java index 2fd62734dc36ce..500f9728961958 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java @@ -237,7 +237,7 @@ private void performDropTable(DropTableStmt stmt) throws DdlException { ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_TABLE, tableName, dbName); } } - catalog.dropTable(TableIdentifier.of(dbName, tableName)); + catalog.dropTable(TableIdentifier.of(dbName, tableName), true); db.setUnInitialized(true); } diff --git a/regression-test/data/external_table_p0/iceberg/iceberg_drop_rest_table.out b/regression-test/data/external_table_p0/iceberg/iceberg_drop_rest_table.out new file mode 100644 index 00000000000000..0d514dfd06186a --- /dev/null +++ b/regression-test/data/external_table_p0/iceberg/iceberg_drop_rest_table.out @@ -0,0 +1,9 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !q0 -- +1 + +-- !q1 -- +1 + +-- !q2 -- + diff --git a/regression-test/suites/external_table_p0/iceberg/iceberg_drop_rest_table.groovy b/regression-test/suites/external_table_p0/iceberg/iceberg_drop_rest_table.groovy new file mode 100644 index 00000000000000..35293a22177e2c --- /dev/null +++ b/regression-test/suites/external_table_p0/iceberg/iceberg_drop_rest_table.groovy @@ -0,0 +1,90 @@ +// 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. + +suite("iceberg_drop_rest_table", "p0,external,doris,external_docker,external_docker_doris") { + + String enabled = context.config.otherConfigs.get("enableIcebergTest") + if (enabled == null || !enabled.equalsIgnoreCase("true")) { + logger.info("disable iceberg test.") + return + } + + String catalog_name = "iceberg_drop_rest_table" + String rest_port = context.config.otherConfigs.get("iceberg_rest_uri_port") + String minio_port = context.config.otherConfigs.get("iceberg_minio_port") + String externalEnvIp = context.config.otherConfigs.get("externalEnvIp") + sql """drop catalog if exists ${catalog_name}""" + sql """ + CREATE CATALOG ${catalog_name} PROPERTIES ( + 'type'='iceberg', + 'iceberg.catalog.type'='rest', + 'uri' = 'http://${externalEnvIp}:${rest_port}', + "s3.access_key" = "admin", + "s3.secret_key" = "password", + "s3.endpoint" = "http://${externalEnvIp}:${minio_port}", + "s3.region" = "us-east-1" + );""" + + String db = "test_db" + String tb = "need_drop_table" + sql """ use ${catalog_name}.${db} """ + + sql """ drop table if exists ${tb} """ + sql """ create table ${tb} (id int) """ + sql """ insert into ${tb} values (1) """ + + + qt_q0 """ + select * from s3( + "uri" = "s3://warehouse/wh/${db}/${tb}/data/*.parquet", + "s3.endpoint"="http://${externalEnvIp}:${minio_port}", + "s3.access_key" = "admin", + "s3.secret_key" = "password", + "s3.region" = "us-east-1", + "format" = "parquet", + "use_path_style" = "true" + ) + """ + + sql """drop user if exists user1""" + sql """create user user1 identified by '12345' """ + sql """ grant all on internal.*.* to user1 """ + sql """ grant SELECT_PRIV on ${catalog_name}.${db}.${tb} to user1 """ + + def result1 = connect(user = 'user1', password = '12345', url = context.config.jdbcUrl) { + sql """ use ${catalog_name}.${db} """ + qt_q1 """ select * from ${tb} """ + test { + sql """ drop table ${tb} """ + exception """Access denied""" + } + } + + sql """ drop table ${tb} """ + // data file should be deleted + qt_q2 """ + select * from s3( + "uri" = "s3://warehouse/wh/${db}/${tb}/data/*.parquet", + "s3.endpoint"="http://${externalEnvIp}:${minio_port}", + "s3.access_key" = "admin", + "s3.secret_key" = "password", + "s3.region" = "us-east-1", + "format" = "parquet", + "use_path_style" = "true" + ) + """ +} \ No newline at end of file