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(" test_alter_table_add_columns" ) {
19+ def tbName = " test_alter_table_add_columns"
20+
21+ sql " DROP TABLE IF EXISTS ${ tbName} FORCE"
22+ sql """
23+ CREATE TABLE `${ tbName} `
24+ (
25+ `siteid` INT DEFAULT '10',
26+ `citycode` SMALLINT,
27+ `username` VARCHAR(32) DEFAULT 'test',
28+ `pv` BIGINT SUM DEFAULT '0'
29+ )
30+ AGGREGATE KEY(`siteid`, `citycode`, `username`)
31+ DISTRIBUTED BY HASH(siteid) BUCKETS 1
32+ PROPERTIES (
33+ "replication_num" = "1"
34+ );
35+ """
36+
37+ sql """ INSERT INTO ${ tbName} VALUES
38+ (1, 1, "xxx", 1),
39+ (2, 2, "xxx", 2),
40+ (3, 3, "xxx", 3);
41+ """
42+
43+ qt_order """ select * from ${ tbName} order by siteid"""
44+
45+ // Add two value column light schema change is true
46+ sql """ alter table ${ tbName} ADD COLUMN (new_v1 INT MAX default "1" , new_v2 INT MAX default "2");"""
47+
48+ qt_order """ select * from ${ tbName} order by siteid"""
49+
50+ sql """ INSERT INTO ${ tbName} VALUES
51+ (4, 4, "yyy", 4, 4, 4),
52+ (5, 5, "yyy", 5, 5, 5),
53+ (6, 6, "yyy", 6, 6, 6);
54+ """
55+
56+ qt_order """ select * from ${ tbName} order by siteid"""
57+
58+ // Add one value column light schema change is false
59+ sleep(1000 )
60+ sql """ alter table ${ tbName} ADD COLUMN (new_k1 INT DEFAULT '1', new_k2 INT DEFAULT '2');"""
61+ def waitSchemaChangeJob = { String tableName /* param */ ->
62+ int tryTimes = 30
63+ while (tryTimes-- > 0 ) {
64+ def jobResult = sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='${ tableName} ' ORDER BY createtime DESC LIMIT 1 """
65+ def jobState = jobResult[0 ][9 ]. toString()
66+ if (' cancelled' . equalsIgnoreCase(jobState)) {
67+ logger. info(" jobResult:{}" , jobResult)
68+ throw new IllegalStateException (" ${ tableName} 's job has been cancelled" )
69+ }
70+ if (' finished' . equalsIgnoreCase(jobState)) {
71+ logger. info(" jobResult:{}" , jobResult)
72+ break
73+ }
74+ sleep(10000 )
75+ }
76+ }
77+
78+ waitSchemaChangeJob(tbName)
79+ qt_sql """ DESC ${ tbName} """
80+
81+ sql """ INSERT INTO ${ tbName} VALUES
82+ (7, 7, "zzz", 7, 7, 7, 7, 7),
83+ (8, 8, "zzz", 8, 8, 8, 8, 8),
84+ (9, 9, "zzz", 9, 9, 9, 9, 9);
85+ """
86+ qt_order """ select * from ${ tbName} order by siteid"""
87+ sql " DROP TABLE IF EXISTS ${ tbName} FORCE"
88+ }
0 commit comments