|
| 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