Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Oct 10, 2024
1 parent 7187484 commit bbe2847
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
5 changes: 5 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ public void checkSchemaChangeAllowed(Column other) throws DdlException {
throw new DdlException("Dest column name is empty");
}

// now nested type can only support change order
if (type.isComplexType() && !type.equals(other.type)) {
throw new DdlException("Can not change " + type + " to " + other);
}

if (!ColumnType.isSchemaChangeAllowed(type, other.type)) {
throw new DdlException("Can not change " + getDataType() + " to " + other.getDataType());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col_array array<text> Yes false \N NONE
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col_map map<char(32),text> Yes false \N NONE
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col_struct struct<f1:varchar(1)> Yes false \N NONE
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

-- !sql --
col0 bigint No true \N
col2 int No false \N NONE
col3 array<int> Yes false \N NONE
col4 map<int,int> Yes false \N NONE
col5 struct<f1:int> Yes false \N NONE

Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,49 @@

suite("create_nestedtypes_with_schemachange", "p0") {

def create_nested_table_and_schema_change = {testTablex, nested_type, column_name ->
def create_nested_table_and_schema_change = {testTablex, nested_type, column_name, error ->
// create basic type
sql "DROP TABLE IF EXISTS $testTablex"
sql """ CREATE TABLE $testTablex (
col0 BIGINT NOT NULL, col2 int NOT NULL
col0 BIGINT NOT NULL, col2 int NOT NULL, col3 array<int> NULL, col4 map<int, int> NULL, col5 struct<f1: int> NULL
)
/* mow */
UNIQUE KEY(col0) DISTRIBUTED BY HASH(col0) BUCKETS 4 PROPERTIES (
"enable_unique_key_merge_on_write" = "true",
"replication_num" = "1"
); """
// alter table add nested type
sql "ALTER TABLE $testTablex ADD COLUMN $column_name $nested_type"
// alter table modify column order
sql "ALTER TABLE $testTablex MODIFY COLUMN $column_name $nested_type AFTER col0"
if (error != '') {
// check nested type do not support other type
test {
sql "ALTER TABLE $testTablex MODIFY COLUMN $column_name $nested_type AFTER col0"
exception (error)
}
} else {
// check nested type can only support change order
sql "ALTER TABLE $testTablex ADD COLUMN $column_name $nested_type"
sql "ALTER TABLE $testTablex MODIFY COLUMN $column_name $nested_type AFTER col0"
waitForSchemaChangeDone {
sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='$testTablex' ORDER BY createtime DESC LIMIT 1 """
time 600
}
}
// desc table
qt_sql "DESC $testTablex"
}

// array
create_nested_table_and_schema_change.call("test_array_schemachange", "ARRAY<STRING>", "col_array")
create_nested_table_and_schema_change.call("test_array_schemachange", "ARRAY<STRING>", "col_array", '')
// map
create_nested_table_and_schema_change.call("test_map_schemachange", "MAP<char(32), string>", "col_map")
create_nested_table_and_schema_change.call("test_map_schemachange", "MAP<char(32), string>", "col_map", '')
// struct
create_nested_table_and_schema_change.call("test_struct_schemachange", "STRUCT<f1: varchar(1)>", "col_struct")
create_nested_table_and_schema_change.call("test_struct_schemachange", "STRUCT<f1: varchar(1)>", "col_struct", '')

// array with other type
create_nested_table_and_schema_change.call("test_array_schemachange_1", "ARRAY<STRING>", "col3", "errCode = 2");
// map with other type
create_nested_table_and_schema_change.call("test_map_schemachange_1", "MAP<char(32), string>", "col4", "errCode = 2");
// struct with other type
create_nested_table_and_schema_change.call("test_struct_schemachange_1", "STRUCT<f1: varchar(1)>", "col5", "errCode = 2");

}

0 comments on commit bbe2847

Please sign in to comment.