yiguolei commented on code in PR #42911: URL: https://github.com/apache/doris/pull/42911#discussion_r1899999652
########## regression-test/suites/schema_change_p0/test_add_keys_light_schema_change.groovy: ########## @@ -0,0 +1,454 @@ +// 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. + +import groovy.json.JsonOutput +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("test_add_keys_light_schema_change") { + def getJobState = { tableName -> + def jobStateResult = sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """ + return jobStateResult[0][9] + } + + def getJobTxnId = { tableName -> + def jobStateResult = sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """ + return jobStateResult[0][8] + } + + def getCreateViewState = { tableName -> + def createViewStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """ + return createViewStateResult[0][8] + } + + def waitJobFinish = { strSql, statePos -> + Object jobStateResult = null + int max_try_time = 2000 + while (max_try_time--){ + jobStateResult = sql """${strSql}""" + def jsonRes = JsonOutput.toJson(jobStateResult) + String result = jobStateResult[0][statePos] + if (result == "FINISHED") { + log.info(jsonRes) + sleep(500) + break + } else { + sleep(100) + if (max_try_time < 1){ + assertEquals(1,2) + } + } + } + return jobStateResult + } + + def tableName = "add_keys_light_schema_change" + try { + + String backend_id; + def backendId_to_backendIP = [:] + def backendId_to_backendHttpPort = [:] + getBackendIpHttpPort(backendId_to_backendIP, backendId_to_backendHttpPort); + + backend_id = backendId_to_backendIP.keySet()[0] + def (code, out, err) = show_be_config(backendId_to_backendIP.get(backend_id), backendId_to_backendHttpPort.get(backend_id)) + + logger.info("Show config: code=" + code + ", out=" + out + ", err=" + err) + assertEquals(code, 0) + def configList = parseJson(out.trim()) + assert configList instanceof List + + boolean disableAutoCompaction = true + for (Object ele in (List) configList) { + assert ele instanceof List<String> + if (((List<String>) ele)[0] == "disable_auto_compaction") { + disableAutoCompaction = Boolean.parseBoolean(((List<String>) ele)[2]) + } + } + int max_try_time = 3000 + List<List<Object>> table_tablets = null; + List<List<Object>> rowset_cnt = null; + + // case 1.1: light schema change type check: add key column in short key column num + sql """ DROP TABLE IF EXISTS add_keys_light_schema_change """ + sql """ + CREATE TABLE IF NOT EXISTS add_keys_light_schema_change ( + `user_id` LARGEINT NOT NULL COMMENT "用户id", + `date` DATEV2 NOT NULL COMMENT "数据灌入日期时间", + `city` VARCHAR(20) COMMENT "用户所在城市", + `age` SMALLINT COMMENT "用户年龄", + `sex` TINYINT COMMENT "用户性别", + + `cost` BIGINT SUM DEFAULT "0" COMMENT "用户总消费", + `max_dwell_time` INT MAX DEFAULT "0" COMMENT "用户最大停留时间", + `hll_col` HLL HLL_UNION NOT NULL COMMENT "HLL列", + `bitmap_col` Bitmap BITMAP_UNION NOT NULL COMMENT "bitmap列") + AGGREGATE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`) + BUCKETS 4 + PROPERTIES ( "replication_num" = "1", "light_schema_change" = "true"); + """ + sql """ + INSERT INTO add_keys_light_schema_change VALUES + (1, '2017-10-01', 'Beijing', 10, 1, 1, 20, hll_hash(1), to_bitmap(1)) + """ + sql """ + ALTER TABLE add_keys_light_schema_change ADD COLUMN new_key_column INT default "2" AFTER user_id PROPERTIES ("timeout"="604800") + """ + + def jobStateResult = waitJobFinish(""" SHOW ALTER TABLE COLUMN WHERE IndexName='add_keys_light_schema_change' ORDER BY createtime DESC LIMIT 1 """, 9) + assertNotEquals(jobStateResult[0][8], "-1") + + qt_sc_11 """ select * from add_keys_light_schema_change order by user_id """ + + sql """ + ALTER TABLE add_keys_light_schema_change ADD COLUMN new_mv_key2 INT default "2" + """ + + jobStateResult = waitJobFinish(""" SHOW ALTER TABLE COLUMN WHERE IndexName='add_keys_light_schema_change' ORDER BY createtime DESC LIMIT 1 """, 9) + assertEquals(jobStateResult[0][8], "-1") + + // case 1.2: light schema change type check: add key column with enable_unique_key_merge_on_write + sql """ DROP TABLE IF EXISTS add_keys_light_schema_change """ + sql """ + CREATE TABLE IF NOT EXISTS add_keys_light_schema_change ( + `user_id` LARGEINT NOT NULL COMMENT "用户id", + `date` DATEV2 NOT NULL COMMENT "数据灌入日期时间", + `city` VARCHAR(20) COMMENT "用户所在城市", + `age` SMALLINT COMMENT "用户年龄", + `sex` TINYINT COMMENT "用户性别", + + `cost` BIGINT DEFAULT "0" COMMENT "用户总消费") + UNIQUE KEY(`user_id`, `date`, `city`, `age`, `sex`) DISTRIBUTED BY HASH(`user_id`) + BUCKETS 4 + PROPERTIES ( + "replication_num" = "1", + "light_schema_change" = "true", + "enable_unique_key_merge_on_write" = "true"); + """ + sql """ + INSERT INTO add_keys_light_schema_change VALUES + (1, '2017-10-01', 'Beijing', 10, 1, 20) + """ + qt_sc_12 """ select * from add_keys_light_schema_change order by user_id """ + + sql """ + ALTER TABLE add_keys_light_schema_change ADD COLUMN new_mv_key1 INT KEY default "2" Review Comment: If the org table is key(col1,col2) you add col3, the new key is (col1,col2,col3) or (col3,col1,col2) or (col1,col3,col2) ? I think you should test all these cases. -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org