From e2ec2afd0f63dfd3e0b28402adea74e7e60739c8 Mon Sep 17 00:00:00 2001 From: Siyang Tang Date: Wed, 12 Feb 2025 11:54:17 +0800 Subject: [PATCH] [chore](rename) Forbid renaming partition columns since this is a buggy feature (#47596) Rename partition columns should also rename column names in partition expressions, but this is not implemented currently. Therefore, forbid renaming partition columns temporarily. --- .../java/org/apache/doris/catalog/Env.java | 24 +++++++--- .../test_dynamic_partition_with_rename.groovy | 37 ++++++++------- .../test_rename_partition_column.groovy | 46 +++++++++++++++++++ 3 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 regression-test/suites/schema_change_p0/test_rename_partition_column.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java index bac854e7ea36a8..26ad816fcda89a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java @@ -5089,6 +5089,13 @@ private void renameColumn(Database db, OlapTable table, String colName, throw new DdlException("Same column name"); } + // @NOTE: Rename partition columns should also rename column names in partition expressions + // but this is not implemented currently. Therefore, forbid renaming partition columns temporarily. + PartitionInfo partitionInfo = table.getPartitionInfo(); + if (partitionInfo.getPartitionColumns().stream().anyMatch(c -> c.getName().equalsIgnoreCase(colName))) { + throw new DdlException("Renaming partition columns has problems, forbidden in current Doris version"); + } + Map indexIdToMeta = table.getIndexIdToMeta(); for (Map.Entry entry : indexIdToMeta.entrySet()) { // rename column is not implemented for table without column unique id. @@ -5148,14 +5155,17 @@ private void renameColumn(Database db, OlapTable table, String colName, throw new DdlException("Column[" + colName + "] does not exists"); } + // @NOTE: Rename partition columns should also rename column names in partition expressions + // but this is not implemented currently. Therefore, forbid renaming partition columns temporarily. + // // 2. modify partition key - PartitionInfo partitionInfo = table.getPartitionInfo(); - List partitionColumns = partitionInfo.getPartitionColumns(); - for (Column column : partitionColumns) { - if (column.getName().equalsIgnoreCase(colName)) { - column.setName(newColName); - } - } + // PartitionInfo partitionInfo = table.getPartitionInfo(); + // List partitionColumns = partitionInfo.getPartitionColumns(); + // for (Column column : partitionColumns) { + // if (column.getName().equalsIgnoreCase(colName)) { + // column.setName(newColName); + // } + //} // 3. modify index List indexes = table.getIndexes(); diff --git a/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_rename.groovy b/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_rename.groovy index facb3790e2a23a..9aa725e9561279 100644 --- a/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_rename.groovy +++ b/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_rename.groovy @@ -38,23 +38,26 @@ suite("test_dynamic_partition_with_rename") { assertEquals(7, result.size()) // rename distributed column, then try to add too more dynamic partition - sql "alter table test_dynamic_partition_with_rename rename column k1 renamed_k1" - sql """ ADMIN SET FRONTEND CONFIG ('dynamic_partition_check_interval_seconds' = '1') """ - sql """ alter table ${tbl} set('dynamic_partition.end'='5') """ - result = sql_return_maparray "show partitions from ${tbl}" - for (def retry = 0; retry < 120; retry++) { // at most wait 120s - if (result.size() == 9) { - break; - } - logger.info("wait dynamic partition scheduler, sleep 1s") - sleep(1000); // sleep 1s - result = sql_return_maparray "show partitions from ${tbl}" - } - assertEquals(9, result.size()) - for (def line = 0; line < result.size(); line++) { - // XXX: DistributionKey at pos(7), next maybe impl by sql meta - assertEquals("renamed_k1", result.get(line).DistributionKey) + test { + sql "alter table test_dynamic_partition_with_rename rename column k1 renamed_k1" + exception """Renaming partition columns has problems, forbidden in current Doris version""" } + // sql """ ADMIN SET FRONTEND CONFIG ('dynamic_partition_check_interval_seconds' = '1') """ + // sql """ alter table ${tbl} set('dynamic_partition.end'='5') """ + // result = sql_return_maparray "show partitions from ${tbl}" + // for (def retry = 0; retry < 120; retry++) { // at most wait 120s + // if (result.size() == 9) { + // break; + // } + // logger.info("wait dynamic partition scheduler, sleep 1s") + // sleep(1000); // sleep 1s + // result = sql_return_maparray "show partitions from ${tbl}" + // } + // assertEquals(9, result.size()) + // for (def line = 0; line < result.size(); line++) { + // // XXX: DistributionKey at pos(7), next maybe impl by sql meta + // assertEquals("renamed_k1", result.get(line).DistributionKey) + // } - sql "drop table test_dynamic_partition_with_rename" + // sql "drop table test_dynamic_partition_with_rename" } diff --git a/regression-test/suites/schema_change_p0/test_rename_partition_column.groovy b/regression-test/suites/schema_change_p0/test_rename_partition_column.groovy new file mode 100644 index 00000000000000..9eedd1cb417e81 --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_rename_partition_column.groovy @@ -0,0 +1,46 @@ +// 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("test_rename_partition_column") { + def tblName = "test_rename_partition_column" + sql """DROP TABLE IF EXISTS ${tblName} FORCE; """ + + sql """ + CREATE TABLE `${tblName}` + ( + `siteid` INT DEFAULT '10', + `citycode` SMALLINT, + `username` VARCHAR(32) DEFAULT 'test', + `pv` BIGINT SUM DEFAULT '0' + ) + AGGREGATE KEY(`siteid`, `citycode`, `username`) + PARTITION BY RANGE(`siteid`) + ( + partition `old_p1` values [("1"), ("2")), + partition `old_p2` values [("2"), ("3")) + ) + DISTRIBUTED BY HASH(siteid) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ); + """ + + test { + sql """ ALTER TABLE ${tblName} RENAME COLUMN siteid new_siteid """ + exception """Renaming partition columns has problems, forbidden in current Doris version""" + } +}