forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix](shcema change)fix alter table faild when modify multiple column…
…s with column changed positions apache#34244 (apache#34692)
- Loading branch information
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
regression-test/suites/alter_p0/test_alter_muti_modify_column.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |