This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 56fdafd3ac5 branch-3.1: [fix](schema-change) Forbid dropping 
distribution columns (#54038)
56fdafd3ac5 is described below

commit 56fdafd3ac57746f6bce93b868168951206005c3
Author: Siyang Tang <[email protected]>
AuthorDate: Wed Jul 30 15:48:12 2025 +0800

    branch-3.1: [fix](schema-change) Forbid dropping distribution columns 
(#54038)
---
 .../apache/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(-)

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 c40277d1dd6..1bd490c9009 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
@@ -491,6 +491,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 1afd51bfab6..9d039e53672 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
@@ -329,7 +329,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 bd600d81698..9b74fe138d9 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
@@ -161,7 +161,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 00000000000..578d792cafc
--- /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..<tables.size()) {
+        def tbl = tables.get(i)
+        def key = keys.get(i)
+        def aggType = aggTypes.get(i)
+        sql """ DROP TABLE IF EXISTS ${tbl} """
+        sql """
+        CREATE TABLE IF NOT EXISTS ${tbl}
+        (
+            k1 DATE,
+            k2 INT DEFAULT '10',
+            v INT ${aggType}
+        ) ${key}
+        DISTRIBUTED BY HASH(k1, k2) BUCKETS 5
+        PROPERTIES("replication_num" = "1", "light_schema_change" = "true"); 
+        """
+
+        test {
+            sql """ ALTER TABLE ${tbl} DROP COLUMN k2"""
+            exception "Could not drop distribution column"
+        }
+    }
+}
diff --git 
a/regression-test/suites/schema_change_p0/test_schema_reordering_dup.groovy 
b/regression-test/suites/schema_change_p0/test_schema_reordering_dup.groovy
index b1f48bd1dcd..2b19c89342a 100644
--- a/regression-test/suites/schema_change_p0/test_schema_reordering_dup.groovy
+++ b/regression-test/suites/schema_change_p0/test_schema_reordering_dup.groovy
@@ -492,7 +492,7 @@ suite("test_schema_reordering_dup", "p0") {
             "               (3, 'Mike Johnson', 77.8, 'Chicago', 35, 1, 
1112223334, true, 30, 3000000000, '2024-06-13', '2024-06-13', '2024-06-13 
11:15:00', '2024-06-13 11:15:00', 'Test String 3', {'a': 300, 'b': 200}, 
'[\"abc\", \"def\"]',95.5, 9.99)," +
             "               (4, 'Emily Brown', 92.0, 'San Francisco', 28, 2, 
5556667778, true, 40, 4000000000, '2024-06-14', '2024-06-14', '2024-06-14 
13:30:00', '2024-06-14 13:30:00', 'Test String 4', {'a': 400, 'b': 200}, 
'[\"abc\", \"def\"]',95.5, 9.99)," +
             "               (5, 'David Wilson', 88.9, 'Seattle', 32, 1, 
9998887776, false, 50, 5000000000, '2024-06-15', '2024-06-15', '2024-06-15 
15:45:00', '2024-06-15 15:45:00', 'Test String 5', {'a': 500, 'b': 200}, 
'[\"abc\", \"def\"]',95.5, 9.99);"
-    errorMessage = "errCode = 2, detailMessage = Table 
regression_test_schema_change_p0.test_schema_reordering_dup check failed"
+    errorMessage = "errCode = 2, detailMessage = Could not drop distribution 
column: username"
     expectException({
         sql initTable
         sql initTableData


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to