Skip to content

Commit 56cdfda

Browse files
authored
[fix](nestedtype) support change order in table for nested type #39210 (#41642)
1 parent d6ecea4 commit 56cdfda

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed

fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java

+5
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ public void checkSchemaChangeAllowed(Column other) throws DdlException {
592592
throw new DdlException("Dest column name is empty");
593593
}
594594

595+
// now nested type can only support change order
596+
if (type.isComplexType() && !type.equals(other.type)) {
597+
throw new DdlException("Can not change " + type + " to " + other);
598+
}
599+
595600
if (!ColumnType.isSchemaChangeAllowed(type, other.type)) {
596601
throw new DdlException("Can not change " + getDataType() + " to " + other.getDataType());
597602
}

fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public abstract class ColumnType {
156156
schemaChangeMatrix[PrimitiveType.DATETIMEV2.ordinal()][PrimitiveType.DATETIMEV2.ordinal()] = true;
157157

158158
// Currently, we do not support schema change between complex types with subtypes.
159-
schemaChangeMatrix[PrimitiveType.ARRAY.ordinal()][PrimitiveType.ARRAY.ordinal()] = false;
160-
schemaChangeMatrix[PrimitiveType.STRUCT.ordinal()][PrimitiveType.STRUCT.ordinal()] = false;
161-
schemaChangeMatrix[PrimitiveType.MAP.ordinal()][PrimitiveType.MAP.ordinal()] = false;
159+
schemaChangeMatrix[PrimitiveType.ARRAY.ordinal()][PrimitiveType.ARRAY.ordinal()] = true;
160+
schemaChangeMatrix[PrimitiveType.STRUCT.ordinal()][PrimitiveType.STRUCT.ordinal()] = true;
161+
schemaChangeMatrix[PrimitiveType.MAP.ordinal()][PrimitiveType.MAP.ordinal()] = true;
162162
}
163163

164164
static boolean isSchemaChangeAllowed(Type lhs, Type rhs) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !sql --
3+
col0 bigint No true \N
4+
col_array array<text> Yes false \N NONE
5+
col2 int No false \N NONE
6+
col3 array<int> Yes false \N NONE
7+
col4 map<int,int> Yes false \N NONE
8+
col5 struct<f1:int> Yes false \N NONE
9+
10+
-- !sql --
11+
col0 bigint No true \N
12+
col_map map<char(32),text> Yes false \N NONE
13+
col2 int No false \N NONE
14+
col3 array<int> Yes false \N NONE
15+
col4 map<int,int> Yes false \N NONE
16+
col5 struct<f1:int> Yes false \N NONE
17+
18+
-- !sql --
19+
col0 bigint No true \N
20+
col_struct struct<f1:varchar(1)> Yes false \N NONE
21+
col2 int No false \N NONE
22+
col3 array<int> Yes false \N NONE
23+
col4 map<int,int> Yes false \N NONE
24+
col5 struct<f1:int> Yes false \N NONE
25+
26+
-- !sql --
27+
col0 bigint No true \N
28+
col2 int No false \N NONE
29+
col3 array<int> Yes false \N NONE
30+
col4 map<int,int> Yes false \N NONE
31+
col5 struct<f1:int> Yes false \N NONE
32+
33+
-- !sql --
34+
col0 bigint No true \N
35+
col2 int No false \N NONE
36+
col3 array<int> Yes false \N NONE
37+
col4 map<int,int> Yes false \N NONE
38+
col5 struct<f1:int> Yes false \N NONE
39+
40+
-- !sql --
41+
col0 bigint No true \N
42+
col2 int No false \N NONE
43+
col3 array<int> Yes false \N NONE
44+
col4 map<int,int> Yes false \N NONE
45+
col5 struct<f1:int> Yes false \N NONE
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("create_nestedtypes_with_schemachange", "p0") {
19+
20+
def create_nested_table_and_schema_change = {testTablex, nested_type, column_name, error ->
21+
// create basic type
22+
sql "DROP TABLE IF EXISTS $testTablex"
23+
sql """ CREATE TABLE $testTablex (
24+
col0 BIGINT NOT NULL, col2 int NOT NULL, col3 array<int> NULL, col4 map<int, int> NULL, col5 struct<f1: int> NULL
25+
)
26+
/* mow */
27+
UNIQUE KEY(col0) DISTRIBUTED BY HASH(col0) BUCKETS 4 PROPERTIES (
28+
"enable_unique_key_merge_on_write" = "true",
29+
"replication_num" = "1"
30+
); """
31+
// alter table add nested type
32+
if (error != '') {
33+
// check nested type do not support other type
34+
test {
35+
sql "ALTER TABLE $testTablex MODIFY COLUMN $column_name $nested_type AFTER col0"
36+
exception (error)
37+
}
38+
} else {
39+
// check nested type can only support change order
40+
sql "ALTER TABLE $testTablex ADD COLUMN $column_name $nested_type"
41+
sql "ALTER TABLE $testTablex MODIFY COLUMN $column_name $nested_type AFTER col0"
42+
waitForSchemaChangeDone {
43+
sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='$testTablex' ORDER BY createtime DESC LIMIT 1 """
44+
time 600
45+
}
46+
}
47+
// desc table
48+
qt_sql "DESC $testTablex"
49+
}
50+
51+
// array
52+
create_nested_table_and_schema_change.call("test_array_schemachange", "ARRAY<STRING>", "col_array", '')
53+
// map
54+
create_nested_table_and_schema_change.call("test_map_schemachange", "MAP<char(32), string>", "col_map", '')
55+
// struct
56+
create_nested_table_and_schema_change.call("test_struct_schemachange", "STRUCT<f1: varchar(1)>", "col_struct", '')
57+
58+
// array with other type
59+
create_nested_table_and_schema_change.call("test_array_schemachange_1", "ARRAY<STRING>", "col3", "errCode = 2");
60+
// map with other type
61+
create_nested_table_and_schema_change.call("test_map_schemachange_1", "MAP<char(32), string>", "col4", "errCode = 2");
62+
// struct with other type
63+
create_nested_table_and_schema_change.call("test_struct_schemachange_1", "STRUCT<f1: varchar(1)>", "col5", "errCode = 2");
64+
65+
}

0 commit comments

Comments
 (0)