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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new ac0176e3354 [fix](shcema change)fix alter table faild when modify 
multiple columns with column changed positions #34244 (#34692)
ac0176e3354 is described below

commit ac0176e3354885c41074951ba0c09ce7d6b51304
Author: huanghg1994 <[email protected]>
AuthorDate: Thu May 23 20:06:40 2024 +0800

    [fix](shcema change)fix alter table faild when modify multiple columns with 
column changed positions #34244 (#34692)
---
 .../apache/doris/alter/SchemaChangeHandler.java    |  4 +-
 .../alter_p0/test_alter_muti_modify_column.groovy  | 82 ++++++++++++++++++++++
 2 files changed, 84 insertions(+), 2 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 f0d57d9625c..a92e3a56d95 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
@@ -476,7 +476,7 @@ public class SchemaChangeHandler extends AlterHandler {
                 found = true;
             }
             if (hasColPos) {
-                if (col.getName().equalsIgnoreCase(columnPos.getLastCol())) {
+                if 
(col.getNonShadowName().equalsIgnoreCase(columnPos.getLastCol())) {
                     lastColIndex = i;
                 }
             } else {
@@ -604,7 +604,7 @@ public class SchemaChangeHandler extends AlterHandler {
                 }
             }
             if (hasColPos) {
-                if (col.getName().equalsIgnoreCase(columnPos.getLastCol())) {
+                if 
(col.getNonShadowName().equalsIgnoreCase(columnPos.getLastCol())) {
                     lastColIndex = i;
                 }
             } else {
diff --git 
a/regression-test/suites/alter_p0/test_alter_muti_modify_column.groovy 
b/regression-test/suites/alter_p0/test_alter_muti_modify_column.groovy
new file mode 100644
index 00000000000..ff11df1f79d
--- /dev/null
+++ b/regression-test/suites/alter_p0/test_alter_muti_modify_column.groovy
@@ -0,0 +1,82 @@
+// 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_alter_muti_modify_column') {
+    def tbl = 'test_alter_muti_modify_column_tbl'
+    sql "DROP TABLE IF EXISTS ${tbl} FORCE"
+    sql """
+        CREATE TABLE ${tbl} (
+            `id` BIGINT NOT NULL,
+            `v1` BIGINT NULL,
+            `v2` VARCHAR(128) NULL,
+            `v3` VARCHAR(128) NULL
+        ) ENGINE=OLAP
+        UNIQUE KEY(`id`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1
+        PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        );
+    """
+
+    sql """
+        INSERT INTO ${tbl} VALUES
+        (1, 10, 'abc', 'def'),
+        (2, 20, 'xyz', 'uvw'),
+        (3, 30, 'pqr', 'lmn');
+    """
+
+    def expectedResults = [
+        [1, 10, 'abc', 'def'],
+        [2, 20, 'xyz', 'uvw'],
+        [3, 30, 'pqr', 'lmn']
+    ]
+
+    // Check data before ALTER TABLE
+    def resultBefore = sql """ SELECT * FROM ${tbl} ORDER BY id """
+    assertEquals(expectedResults.size(), resultBefore.size())
+    for (int i = 0; i < expectedResults.size(); i++) {
+        for (int j = 0; j < expectedResults[i].size(); j++) {
+            assertEquals(expectedResults[i][j], resultBefore[i][j])
+        }
+    }
+
+    sql """
+        ALTER TABLE ${tbl} 
+        MODIFY COLUMN `v2` VARCHAR(512) NULL AFTER `v1`,
+        MODIFY COLUMN `v3` VARCHAR(512) NULL AFTER `v2`;
+    """
+
+    // Wait for ALTER TABLE to take effect
+    Thread.sleep(5000)
+
+    // Check table structure after ALTER TABLE
+    def resultCreate = sql """ SHOW CREATE TABLE ${tbl} """
+    def createTbl = resultCreate[0][1].toString().toLowerCase()
+    assertTrue(createTbl.indexOf("`v2` varchar(512) null") > 0)
+    assertTrue(createTbl.indexOf("`v3` varchar(512) null") > 0)
+
+    // Check data after ALTER TABLE
+    def resultAfter = sql """ SELECT * FROM ${tbl} ORDER BY id """
+    assertEquals(expectedResults.size(), resultAfter.size())
+    for (int i = 0; i < expectedResults.size(); i++) {
+        for (int j = 0; j < expectedResults[i].size(); j++) {
+            assertEquals(expectedResults[i][j], resultAfter[i][j])
+        }
+    }
+
+    sql "DROP TABLE IF EXISTS ${tbl} FORCE"
+}
\ No newline at end of file


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

Reply via email to