From 90dd2dfe198b2009ca23a835e3ebbeef128ff165 Mon Sep 17 00:00:00 2001 From: Siyang Tang Date: Fri, 1 Aug 2025 11:47:48 +0800 Subject: [PATCH] [fix](schema-change) Forbid dropping distribution columns (branch-2.1) (#54039) ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason - Behavior changed: - [ ] No. - [ ] Yes. - Does this need documentation? - [ ] No. - [ ] Yes. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label --- .../doris/alter/SchemaChangeHandler.java | 3 ++ .../test_multi_column_partition.groovy | 2 +- .../test_alter_table_drop_column.groovy | 2 +- .../test_disable_drop_bucket_columns.groovy | 43 +++++++++++++++++++ .../test_schema_reordering_dup.groovy | 2 +- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 regression-test/suites/schema_change_p0/test_disable_drop_bucket_columns.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java index 1d9fd18e3d..7013e1a961 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java @@ -466,6 +466,9 @@ public class SchemaChangeHandler extends AlterHandler { throw new DdlException("Column does not exists: " + dropColName); } } + if (olapTable.isDistributionColumn(dropColName)) { + throw new DdlException("Could not drop distribution column: " + dropColName); + } return lightSchemaChange; } diff --git a/regression-test/suites/partition_p0/multi_partition/test_multi_column_partition.groovy b/regression-test/suites/partition_p0/multi_partition/test_multi_column_partition.groovy index 0f4c41bc7f..7b8aa7b425 100644 --- a/regression-test/suites/partition_p0/multi_partition/test_multi_column_partition.groovy +++ b/regression-test/suites/partition_p0/multi_partition/test_multi_column_partition.groovy @@ -328,7 +328,7 @@ suite("test_multi_partition_key", "p0") { assertEquals("FINISHED", getAlterColumnFinalState("test_multi_column_drop_partition_column")) test { sql "ALTER TABLE test_multi_column_drop_partition_column DROP COLUMN k1" - exception "Partition column[k1] cannot be dropped" + exception "Could not drop distribution column: k1" } sql "insert into test_multi_column_drop_partition_column " + "values(100, 0, 0, 0, 0, '2000-01-01 00:00:00', 0.001, -0.001, 0.001)" diff --git a/regression-test/suites/schema_change_p0/test_alter_table_drop_column.groovy b/regression-test/suites/schema_change_p0/test_alter_table_drop_column.groovy index 163f1267aa..a42588a80e 100644 --- a/regression-test/suites/schema_change_p0/test_alter_table_drop_column.groovy +++ b/regression-test/suites/schema_change_p0/test_alter_table_drop_column.groovy @@ -171,7 +171,7 @@ suite("test_alter_table_drop_column") { test { sql """alter table ${dupTableName} drop COLUMN siteid;""" // check exception message contains - exception "Distribution column[siteid] cannot be dropped" + exception "Could not drop distribution column: siteid" } sql "DROP TABLE IF EXISTS ${dupTableName} FORCE" diff --git a/regression-test/suites/schema_change_p0/test_disable_drop_bucket_columns.groovy b/regression-test/suites/schema_change_p0/test_disable_drop_bucket_columns.groovy new file mode 100644 index 0000000000..578d792caf --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_disable_drop_bucket_columns.groovy @@ -0,0 +1,43 @@ +// 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_disable_drop_bucket_columns") { + def tables = ["test_disable_drop_bucket_columns_dup", "test_disable_drop_bucket_columns_agg"] + def keys = ["DUPLICATE KEY(k1, k2)", "AGGREGATE KEY(k1, k2)"] + def aggTypes = ["", "SUM"] + for (i in 0..