From 56cdfda427c773c39143fbf3b598ce5428a0a349 Mon Sep 17 00:00:00 2001 From: amory Date: Mon, 14 Oct 2024 08:26:56 +0800 Subject: [PATCH] [fix](nestedtype) support change order in table for nested type #39210 (#41642) --- .../java/org/apache/doris/catalog/Column.java | 5 ++ .../org/apache/doris/catalog/ColumnType.java | 6 +- .../create_nestedtypes_with_schemachange.out | 46 +++++++++++++ ...reate_nestedtypes_with_schemachange.groovy | 65 +++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 regression-test/data/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.out create mode 100644 regression-test/suites/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java index 527e22cbecdbce..cdeef303eba899 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java @@ -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()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java index d4813dbc8200ff..7f26daf86f8141 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java @@ -156,9 +156,9 @@ public abstract class ColumnType { schemaChangeMatrix[PrimitiveType.DATETIMEV2.ordinal()][PrimitiveType.DATETIMEV2.ordinal()] = true; // Currently, we do not support schema change between complex types with subtypes. - schemaChangeMatrix[PrimitiveType.ARRAY.ordinal()][PrimitiveType.ARRAY.ordinal()] = false; - schemaChangeMatrix[PrimitiveType.STRUCT.ordinal()][PrimitiveType.STRUCT.ordinal()] = false; - schemaChangeMatrix[PrimitiveType.MAP.ordinal()][PrimitiveType.MAP.ordinal()] = false; + schemaChangeMatrix[PrimitiveType.ARRAY.ordinal()][PrimitiveType.ARRAY.ordinal()] = true; + schemaChangeMatrix[PrimitiveType.STRUCT.ordinal()][PrimitiveType.STRUCT.ordinal()] = true; + schemaChangeMatrix[PrimitiveType.MAP.ordinal()][PrimitiveType.MAP.ordinal()] = true; } static boolean isSchemaChangeAllowed(Type lhs, Type rhs) { diff --git a/regression-test/data/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.out b/regression-test/data/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.out new file mode 100644 index 00000000000000..af88eb6b9bb042 --- /dev/null +++ b/regression-test/data/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.out @@ -0,0 +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 +col_array array Yes false \N NONE +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + +-- !sql -- +col0 bigint No true \N +col_map map Yes false \N NONE +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + +-- !sql -- +col0 bigint No true \N +col_struct struct Yes false \N NONE +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + +-- !sql -- +col0 bigint No true \N +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + +-- !sql -- +col0 bigint No true \N +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + +-- !sql -- +col0 bigint No true \N +col2 int No false \N NONE +col3 array Yes false \N NONE +col4 map Yes false \N NONE +col5 struct Yes false \N NONE + diff --git a/regression-test/suites/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.groovy b/regression-test/suites/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.groovy new file mode 100644 index 00000000000000..ec0f163821d16a --- /dev/null +++ b/regression-test/suites/datatype_p0/nested_types/ddl/create_nestedtypes_with_schemachange.groovy @@ -0,0 +1,65 @@ +// 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("create_nestedtypes_with_schemachange", "p0") { + + 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, col3 array NULL, col4 map NULL, col5 struct 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 + 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", "col_array", '') + // map + create_nested_table_and_schema_change.call("test_map_schemachange", "MAP", "col_map", '') + // struct + create_nested_table_and_schema_change.call("test_struct_schemachange", "STRUCT", "col_struct", '') + + // array with other type + create_nested_table_and_schema_change.call("test_array_schemachange_1", "ARRAY", "col3", "errCode = 2"); + // map with other type + create_nested_table_and_schema_change.call("test_map_schemachange_1", "MAP", "col4", "errCode = 2"); + // struct with other type + create_nested_table_and_schema_change.call("test_struct_schemachange_1", "STRUCT", "col5", "errCode = 2"); + +}