Copilot commented on code in PR #61213: URL: https://github.com/apache/doris/pull/61213#discussion_r2916208914
########## regression-test/suites/schema_change_p0/test_agg_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_agg_schema_key_add_light", "p0") { + def tbName1 = "test_agg_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT SUM COMMENT \"用户年龄\",\n" + + " `sex` TINYINT MAX COMMENT \"用户性别\",\n" + + " `phone` LARGEINT MAX COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) REPLACE DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME REPLACE DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " AGGREGATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. Review Comment: The comment says "Add a new key column with DATE type" but the statement adds `decimal_light DECIMAL KEY`. This mismatch is confusing when diagnosing failures; please update the comment (or the column type/name) to match what the test actually does. ```suggestion // Add a new key column with DECIMAL type. Expected is a light schema change. ``` ########## regression-test/suites/schema_change_p0/test_agg_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_agg_schema_key_add_light", "p0") { + def tbName1 = "test_agg_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT SUM COMMENT \"用户年龄\",\n" + + " `sex` TINYINT MAX COMMENT \"用户性别\",\n" + + " `phone` LARGEINT MAX COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) REPLACE DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME REPLACE DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " AGGREGATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column decimal_light DECIMAL KEY; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column as the 1st column with DATE type. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column decimal_heavy DATE KEY FIRST; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + sql """ alter table ${tbName1} rename column decimal_heavy decimal_heavy_new; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + qt_sql """ select * from ${tbName1} where decimal_heavy_new = 0.111; """ Review Comment: The final assertion query compares `decimal_heavy_new` (a DATE column) to a numeric literal (`0.111`). This depends on implicit type casting and doesn’t validate the schema change meaningfully; consider asserting against an appropriate DATE value (or querying a DECIMAL column if that was the intent). ```suggestion qt_sql """ select * from ${tbName1} where decimal_heavy_new = '2025-01-01'; """ ``` ########## regression-test/suites/schema_change_p0/test_agg_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_agg_schema_key_add_light", "p0") { + def tbName1 = "test_agg_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT SUM COMMENT \"用户年龄\",\n" + + " `sex` TINYINT MAX COMMENT \"用户性别\",\n" + + " `phone` LARGEINT MAX COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) REPLACE DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME REPLACE DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " AGGREGATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column decimal_light DECIMAL KEY; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column as the 1st column with DATE type. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column decimal_heavy DATE KEY FIRST; """ Review Comment: `decimal_heavy` is declared as a `DATE` column, but the name implies a DECIMAL type. Renaming it to reflect its DATE semantics would make the test intent clearer (and avoid confusion later when it’s renamed again). ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT COMMENT \"用户年龄\",\n" + + " `sex` TINYINT COMMENT \"用户性别\",\n" + + " `phone` LARGEINT COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " DUPLICATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData Review Comment: This suite is for a DUPLICATE table, but the comment says "AGGREGATE model". Please update the comment to match the table model under test. ########## fe/fe-common/src/main/java/org/apache/doris/common/Config.java: ########## @@ -2788,6 +2788,12 @@ public class Config extends ConfigBase { }) public static boolean enable_convert_light_weight_schema_change = false; + @ConfField(mutable = true, masterOnly = true, description = { + "暂时性配置项,开启后加 key 列采用轻量级实现", + "temporary config filed, will enable light weight add key column" + }) Review Comment: The English description has typos/wording issues (e.g., "config filed" -> "config field", and "light weight" -> "lightweight"). Since this string is user-facing via `SHOW FRONTEND CONFIG`, it’s worth fixing for clarity. ########## regression-test/suites/schema_change_p0/test_agg_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_agg_schema_key_add_light", "p0") { + def tbName1 = "test_agg_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } Review Comment: `lightAddKeyConfig` is read once at the beginning and then used to decide whether to assert light vs heavy via `TransactionId`. This makes the test environment-dependent (and the PR description claims both enabled/disabled are validated, but the suite never toggles the config). Consider explicitly setting `enable_light_add_key` with `ADMIN SET FRONTEND CONFIG` (save/restore the original value in a try/finally) and make `checkAddKey` assert purely based on the expected light/heavy outcome for the current phase (or re-query the config after each toggle). ########## regression-test/framework/src/main/groovy/org/apache/doris/regression/util/DebugPoint.groovy: ########## @@ -56,6 +56,11 @@ class DebugPoint { Http.checkHttpResult(result, type) } + static def enableFeDebugPoint(String host, int httpPort, String name, Map<String, String> params = null) { + enableDebugPoint(host, httpPort, NodeType.FE, name, params) + } Review Comment: PR description mentions adding `clearDebugPointsForAllBEs`, but this diff adds `enableFeDebugPoint`. If the description is out of date, please update it; otherwise, the intended helper change seems missing from the PR. ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } Review Comment: `lightAddKeyConfig` is read once at the beginning and then used to decide whether to assert light vs heavy via `TransactionId`. This makes the test environment-dependent (and the PR description claims both enabled/disabled are validated, but the suite never toggles the config). Consider explicitly setting `enable_light_add_key` with `ADMIN SET FRONTEND CONFIG` (save/restore the original value in a try/finally) and make `checkAddKey` assert purely based on the expected light/heavy outcome for the current phase (or re-query the config after each toggle). ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT COMMENT \"用户年龄\",\n" + + " `sex` TINYINT COMMENT \"用户性别\",\n" + + " `phone` LARGEINT COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " DUPLICATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. Review Comment: The comment says "Add a new key column with DATE type" but the statement adds `decimal_light DECIMAL KEY`. This mismatch is confusing when diagnosing failures; please update the comment (or the column type/name) to match what the test actually does. ```suggestion // Add a new DECIMAL key column. Expected is a light schema change. ``` ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ Review Comment: This suite is for a DUPLICATE table, but the comment says "AGGREGATE model". Please update the comment to avoid misleading future readers. ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT COMMENT \"用户年龄\",\n" + + " `sex` TINYINT COMMENT \"用户性别\",\n" + + " `phone` LARGEINT COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " DUPLICATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column decimal_light DECIMAL KEY; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column as the 1st column with DATE type. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column decimal_heavy DATE KEY FIRST; """ Review Comment: `decimal_heavy` is declared as a `DATE` column, but the name implies a DECIMAL type. Renaming it to reflect its DATE semantics would make the test intent clearer (and avoid confusion later when it’s renamed again). ########## regression-test/suites/schema_change_p0/test_dup_schema_key_add_light.groovy: ########## @@ -0,0 +1,173 @@ +// 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("test_dup_schema_key_add_light", "p0") { + def tbName1 = "test_dup_schema_key_add_light1" + def getTableStatusSql = " SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1 " + + def lightAddKeyConfig = sql_return_maparray " SHOW FRONTEND CONFIG like 'enable_light_add_key'" + + def checkAddKey = { mayBeLight -> + def result = sql_return_maparray getTableStatusSql + if (lightAddKeyConfig[0].value == "true" && mayBeLight) { + assert result[0].TransactionId == -1 + } else { + assert result[0].TransactionId != -1 + } + } + + + //Test the AGGREGATE model by adding a key column + sql """ DROP TABLE IF EXISTS ${tbName1} """ + def initTable = " CREATE TABLE IF NOT EXISTS ${tbName1}\n" + + " (\n" + + " `user_id` LARGEINT NOT NULL COMMENT \"用户id\",\n" + + " `username` VARCHAR(50) NOT NULL COMMENT \"用户昵称\",\n" + + " `city` VARCHAR(20) COMMENT \"用户所在城市\",\n" + + " `age` SMALLINT COMMENT \"用户年龄\",\n" + + " `sex` TINYINT COMMENT \"用户性别\",\n" + + " `phone` LARGEINT COMMENT \"用户电话\",\n" + + " `address` VARCHAR(500) DEFAULT \"青海省西宁市城东区\"COMMENT \"用户地址\",\n" + + " `register_time` DATETIME DEFAULT \"1970-01-01 00:00:00\" COMMENT \"用户注册时间\"\n" + + " )\n" + + " DUPLICATE KEY(`user_id`, `username`, `city`)\n" + + " DISTRIBUTED BY HASH(`user_id`) BUCKETS 1\n" + + " PROPERTIES (\n" + + " \"replication_allocation\" = \"tag.location.default: 1\"\n" + + " );" + + def initTableData = "insert into ${tbName1} values(123456789, 'Alice', 'Beijing', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00')," + + " (234567890, 'Bob', 'Shanghai', 30, 1, 13998765432, 'No. 456 Street, Shanghai', '2022-02-02 12:00:00')," + + " (345678901, 'Carol', 'Guangzhou', 28, 0, 13724681357, 'No. 789 Street, Guangzhou', '2022-03-03 14:00:00')," + + " (456789012, 'Dave', 'Shenzhen', 35, 1, 13680864279, 'No. 987 Street, Shenzhen', '2022-04-04 16:00:00')," + + " (567890123, 'Eve', 'Chengdu', 27, 0, 13572468091, 'No. 654 Street, Chengdu', '2022-05-05 18:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (678901234, 'Frank', 'Hangzhou', 32, 1, 13467985213, 'No. 321 Street, Hangzhou', '2022-06-06 20:00:00')," + + " (789012345, 'Grace', 'Xian', 29, 0, 13333333333, 'No. 222 Street, Xian', '2022-07-07 22:00:00');" + + //Test the AGGREGATE model by adding a key column with INT + sql initTable + sql initTableData + + // Add a new key column with INT type with specified pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price INT KEY DEFAULT "999" AFTER `city`; """ + def insertSql = " insert into ${tbName1} values(923456689, 'Alice','Yaan', 22536, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + sql "insert into ${tbName1} values(923456689, 'Alice','Beijing', 999, 25, 0, 13812345679, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with INT type without pos. Expected is a light schema change. + sql """ alter table ${tbName1} add column house_price1 INT KEY; """ + insertSql = " insert into ${tbName1} values(923456689, 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type before shortkey. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column heavy VARCHAR(20) KEY DEFAULT "heavy_sc" AFTER `user_id`; """ + insertSql = " insert into ${tbName1} values(923456689, 'heavy_sc_insert', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + // Add a new key column with VARCHAR type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid VARCHAR(16) KEY DEFAULT "light_mid" AFTER `heavy`; """ + + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} where user_id = 234567890 and light_mid = 'light_mid' """ + + qt_sql """ select * from ${tbName1} where user_id = 234567890; """ + + // a heavy schema change after light schema change without writing. + sql """ alter table ${tbName1} add column heavy_mid VARCHAR(16) KEY DEFAULT "heavy_mid" AFTER `user_id`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, "", false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column light_mid1 DATE KEY AFTER `heavy_mid`; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values(923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column with DATE type after shortkey. Expected is a light schema change. + sql """ alter table ${tbName1} add column decimal_light DECIMAL KEY; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + // Add a new key column as the 1st column with DATE type. Expected is a heavy schema change. + sql """ alter table ${tbName1} add column decimal_heavy DATE KEY FIRST; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(false) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + insertSql = " insert into ${tbName1} values('2025-01-01', 923456689, 'heavy_mid', '2020-04-01', 'heavy_sc_insert', 'light-mid', 'Alice', 'Yaan', 22536, 1, 35.01, 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + + sql """ alter table ${tbName1} rename column decimal_heavy decimal_heavy_new; """ + waitForSchemaChangeDone({ + sql getTableStatusSql + time 600 + }, insertSql, false, "${tbName1}") + checkAddKey(true) + + qt_sql """ select * from ${tbName1} order by user_id; """ + + qt_sql """ select * from ${tbName1} where decimal_heavy_new = 0.111; """ Review Comment: The final assertion query compares `decimal_heavy_new` (a DATE column) to a numeric literal (`0.111`). This depends on implicit type casting and doesn’t validate the schema change meaningfully; consider asserting against an appropriate DATE value (or querying a DECIMAL column if that was the intent). ```suggestion qt_sql """ select * from ${tbName1} where decimal_heavy_new = '2025-01-01'; """ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
