From dee7dc39dd43085795890cbbf36989c5e3810f76 Mon Sep 17 00:00:00 2001 From: wyxxxcat <1520358997@qq.com> Date: Sun, 12 Jan 2025 20:49:58 +0800 Subject: [PATCH] 1 --- regression-test/common/helper.groovy | 5 +- .../add_drop/test_ds_rollup_add_drop.groovy | 117 ++++++++++++++ .../rename/test_ds_rollup_rename.groovy | 102 ++++++++++++ .../add/test_ds_rollup_col_add.groovy | 102 ++++++++++++ .../drop/test_ds_rollup_col_drop.groovy | 105 ++++++++++++ .../test_ds_rollup_col_order_by.groovy | 86 ++++++++++ .../alter_type/test_tsa_col_alter_type.groovy | 116 +++++++++++++ .../column/basic/test_tsa_col_basic.groovy | 152 ++++++++++++++++++ .../drop_key/test_tsa_col_drop_key_col.groovy | 101 ++++++++++++ .../drop_val/test_tsa_col_drop_val_col.groovy | 100 ++++++++++++ .../order_by/test_tsa_col_order_by.groovy | 94 +++++++++++ .../column/rename/test_tsa_col_rename.groovy | 125 ++++++++++++++ .../add_drop/test_tsa_rollup_add_drop.groovy | 120 ++++++++++++++ .../rename/test_tsa_rollup_rename.groovy | 105 ++++++++++++ .../add/test_tsa_rollup_col_add.groovy | 105 ++++++++++++ .../drop/test_tsa_rollup_col_drop.groovy | 108 +++++++++++++ .../test_tsa_rollup_col_order_by.groovy | 89 ++++++++++ 17 files changed, 1731 insertions(+), 1 deletion(-) create mode 100644 regression-test/suites/db_sync/rollup/add_drop/test_ds_rollup_add_drop.groovy create mode 100644 regression-test/suites/db_sync/rollup/rename/test_ds_rollup_rename.groovy create mode 100644 regression-test/suites/db_sync/rollup_col/add/test_ds_rollup_col_add.groovy create mode 100644 regression-test/suites/db_sync/rollup_col/drop/test_ds_rollup_col_drop.groovy create mode 100644 regression-test/suites/db_sync/rollup_col/order_by/test_ds_rollup_col_order_by.groovy create mode 100644 regression-test/suites/table_sync_alias/column/alter_type/test_tsa_col_alter_type.groovy create mode 100644 regression-test/suites/table_sync_alias/column/basic/test_tsa_col_basic.groovy create mode 100644 regression-test/suites/table_sync_alias/column/drop_key/test_tsa_col_drop_key_col.groovy create mode 100644 regression-test/suites/table_sync_alias/column/drop_val/test_tsa_col_drop_val_col.groovy create mode 100644 regression-test/suites/table_sync_alias/column/order_by/test_tsa_col_order_by.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rename/test_tsa_col_rename.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rollup/add_drop/test_tsa_rollup_add_drop.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rollup/rename/test_tsa_rollup_rename.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rollup_col/add/test_tsa_rollup_col_add.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rollup_col/drop/test_tsa_rollup_col_drop.groovy create mode 100644 regression-test/suites/table_sync_alias/column/rollup_col/order_by/test_tsa_rollup_col_order_by.groovy diff --git a/regression-test/common/helper.groovy b/regression-test/common/helper.groovy index a70ce8cc..875822d6 100644 --- a/regression-test/common/helper.groovy +++ b/regression-test/common/helper.groovy @@ -424,13 +424,16 @@ class Helper { if (source == "sql") { res = suite.sql_return_maparray "DESC ${table} ALL" } else { + if (alias != null) { + table = alias + } res = suite.target_sql_return_maparray "DESC ${table} ALL" } def map = Maps.newHashMap() def index = "" for (def row : res) { - if (row.IndexName != "") { + if (row.IndexName != "" && row.IndexName != table) { index = row.IndexName } if (row.Field == "") { diff --git a/regression-test/suites/db_sync/rollup/add_drop/test_ds_rollup_add_drop.groovy b/regression-test/suites/db_sync/rollup/add_drop/test_ds_rollup_add_drop.groovy new file mode 100644 index 00000000..2fec7388 --- /dev/null +++ b/regression-test/suites/db_sync/rollup/add_drop/test_ds_rollup_add_drop.groovy @@ -0,0 +1,117 @@ +// 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_ds_rollup_add_drop') { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", 'helper.groovy')) + + if (helper.has_feature('feature_skip_rollup_binlogs')) { + logger.info('skip this suite because feature_skip_rollup_binlogs is enabled') + return + } + + def tableName = 'tbl_' + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_full (id, col2, col4) + """ + + def rollupFullFinished = { res -> Boolean + for (List row : res) { + if ((row[5] as String).contains("rollup_${tableName}_full")) { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + rollupFullFinished, 30)) + sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")""" + + logger.info('=== Test 1: full update rollup ===') + helper.ccrJobDelete() + helper.ccrJobCreate() + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + def hasRollupFull = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL", + hasRollupFull, 30, 'target')) + + logger.info('=== Test 2: incremental update rollup ===') + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_incr (id, col1, col3) + """ + def hasRollupIncremental = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_incr") { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL", + hasRollupIncremental, 30, 'target')) + + logger.info('=== Test 3: drop rollup') + sql """ + ALTER TABLE ${tableName} DROP ROLLUP rollup_${tableName}_incr + """ + + def hasRollupIncrementalDropped = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_incr") { + return false + } + } + return true + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL", + hasRollupIncrementalDropped, 30, 'target')) +} diff --git a/regression-test/suites/db_sync/rollup/rename/test_ds_rollup_rename.groovy b/regression-test/suites/db_sync/rollup/rename/test_ds_rollup_rename.groovy new file mode 100644 index 00000000..79f2b8ac --- /dev/null +++ b/regression-test/suites/db_sync/rollup/rename/test_ds_rollup_rename.groovy @@ -0,0 +1,102 @@ +// 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_ds_rollup_rename") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + if (helper.has_feature("feature_skip_rollup_binlogs")) { + logger.info("skip this suite because feature_skip_rollup_binlogs is enabled") + return + } + + def tableName = "tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_full (id, col2, col4) + """ + + def rollupFullFinished = { res -> Boolean + for (List row : res) { + if ((row[5] as String).contains("rollup_${tableName}_full")) { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + rollupFullFinished, 30)) + sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")""" + + logger.info("=== Test 1: full update rollup ===") + helper.ccrJobDelete() + helper.ccrJobCreate() + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + def hasRollupFull = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL", + hasRollupFull, 30, "target")) + + logger.info("=== Test 2: Rename rollup ===") + sql """ + ALTER TABLE ${tableName} + RENAME ROLLUP rollup_${tableName}_full rollup_${tableName}_full_new + """ + def hasRollupFullNew = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full_new") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${tableName} ALL", + hasRollupFullNew, 30, "target")) +} diff --git a/regression-test/suites/db_sync/rollup_col/add/test_ds_rollup_col_add.groovy b/regression-test/suites/db_sync/rollup_col/add/test_ds_rollup_col_add.groovy new file mode 100644 index 00000000..b96536c4 --- /dev/null +++ b/regression-test/suites/db_sync/rollup_col/add/test_ds_rollup_col_add.groovy @@ -0,0 +1,102 @@ +// 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_ds_rollup_col_add") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete() + helper.ccrJobCreate() + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: add key column ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `key` INT KEY DEFAULT "0" + TO rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 2: add value column ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `first_value` INT DEFAULT "0" + TO rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(2), 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) +} diff --git a/regression-test/suites/db_sync/rollup_col/drop/test_ds_rollup_col_drop.groovy b/regression-test/suites/db_sync/rollup_col/drop/test_ds_rollup_col_drop.groovy new file mode 100644 index 00000000..bb712dca --- /dev/null +++ b/regression-test/suites/db_sync/rollup_col/drop/test_ds_rollup_col_drop.groovy @@ -0,0 +1,105 @@ +// 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_ds_rollup_col_drop") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DUPLICATE KEY(`id`, `col1`, `col2`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete() + helper.ccrJobCreate() + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: drop key column ===") + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `col2` + FROM rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 2: drop value column ===") + + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `col4` + FROM rollup_${tableName} + """ + sql "sync" + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(2), 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) +} diff --git a/regression-test/suites/db_sync/rollup_col/order_by/test_ds_rollup_col_order_by.groovy b/regression-test/suites/db_sync/rollup_col/order_by/test_ds_rollup_col_order_by.groovy new file mode 100644 index 00000000..393ad4c5 --- /dev/null +++ b/regression-test/suites/db_sync/rollup_col/order_by/test_ds_rollup_col_order_by.groovy @@ -0,0 +1,86 @@ +// 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_ds_rollup_col_order_by") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete() + helper.ccrJobCreate() + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: order by columns ===") + sql """ + ALTER TABLE ${tableName} + ORDER BY (col2, id, col4) + FROM rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) +} + diff --git a/regression-test/suites/table_sync_alias/column/alter_type/test_tsa_col_alter_type.groovy b/regression-test/suites/table_sync_alias/column/alter_type/test_tsa_col_alter_type.groovy new file mode 100644 index 00000000..7c0c5eec --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/alter_type/test_tsa_col_alter_type.groovy @@ -0,0 +1,116 @@ +// 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_tsa_col_alter_type") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + def value_is_big_int = { res -> Boolean + // Field == 'value' && 'Type' == 'bigint' + return res[2][0] == 'value' && res[2][1] == 'bigint' + } + + def id_is_big_int = { res -> Boolean + // Field == 'id' && 'Type' == 'bigint' + return res[1][0] == 'id' && res[1][1] == 'bigint' + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT, + `value` INT + ) + ENGINE=OLAP + UNIQUE KEY(`test`, `id`) + DISTRIBUTED BY HASH(test) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 1: add key column type ===") + + sql """ + ALTER TABLE ${tableName} + MODIFY COLUMN `id` BIGINT KEY + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${tableName}`", id_is_big_int, 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${aliasTableName}`", id_is_big_int, 60, "target_sql")) + + logger.info("=== Test 2: alter value column type ===") + + sql """ + ALTER TABLE ${tableName} + MODIFY COLUMN `value` BIGINT + """ + + logger.info("=== Test 2: Check column type ===") + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(2), 30)) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", value_is_big_int, 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", value_is_big_int, 60, "target_sql")) +} + diff --git a/regression-test/suites/table_sync_alias/column/basic/test_tsa_col_basic.groovy b/regression-test/suites/table_sync_alias/column/basic/test_tsa_col_basic.groovy new file mode 100644 index 00000000..2ae193b1 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/basic/test_tsa_col_basic.groovy @@ -0,0 +1,152 @@ +// 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_tsa_col_basic") { + // 1. add first key column + // 2. add last key column + // 3. add value column + // 4. add last value column + + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT, + `value` INT + ) + ENGINE=OLAP + UNIQUE KEY(`test`, `id`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + sql "sync" + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 1: add first column case ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `first` INT KEY DEFAULT "0" FIRST + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + def has_column_first = { res -> Boolean + // Field == 'first' && 'Key' == 'YES' + return res[0][0] == 'first' && (res[0][3] == 'YES' || res[0][3] == 'true') + } + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${aliasTableName}`", has_column_first, 60, "target_sql")) + + logger.info("=== Test 2: add column after last key ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `last` INT KEY DEFAULT "0" AFTER `id` + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(2), 30)) + + def has_column_last = { res -> Boolean + // Field == 'last' && 'Key' == 'YES' + return res[3][0] == 'last' && (res[3][3] == 'YES' || res[3][3] == 'true') + } + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${aliasTableName}`", has_column_last, 60, "target_sql")) + + logger.info("=== Test 3: add value column after last key ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `first_value` INT DEFAULT "0" AFTER `last` + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(3), 30)) + + def has_column_first_value = { res -> Boolean + // Field == 'first_value' && 'Key' == 'NO' + return res[4][0] == 'first_value' && (res[4][3] == 'NO' || res[4][3] == 'false') + } + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${aliasTableName}`", has_column_first_value, 60, "target_sql")) + + logger.info("=== Test 4: add value column last ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `last_value` INT DEFAULT "0" AFTER `value` + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(4), 30)) + + def has_column_last_value = { res -> Boolean + // Field == 'last_value' && 'Key' == 'NO' + return res[6][0] == 'last_value' && (res[6][3] == 'NO' || res[6][3] == 'false') + } + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM `${aliasTableName}`", has_column_last_value, 60, "target_sql")) +} + diff --git a/regression-test/suites/table_sync_alias/column/drop_key/test_tsa_col_drop_key_col.groovy b/regression-test/suites/table_sync_alias/column/drop_key/test_tsa_col_drop_key_col.groovy new file mode 100644 index 00000000..662e3f94 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/drop_key/test_tsa_col_drop_key_col.groovy @@ -0,0 +1,101 @@ +// 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_tsa_col_drop_key") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + def id_column_not_exists = { res -> Boolean + def not_exists = true + for (int i = 0; i < res.size(); i++) { + if (res[i][0] == 'id') { + not_exists = false + } + } + return not_exists + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT, + `value` INT + ) + ENGINE=OLAP + DUPLICATE KEY(`test`, `id`) + DISTRIBUTED BY HASH(test) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + logger.info("=== Test 1: add data and sync create ===") + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 2: drop key column ===") + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `id` + """ + sql "sync" + + logger.info("=== Test 2: Check key column ===") + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", id_column_not_exists, 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", id_column_not_exists, 60, "target_sql")) +} + diff --git a/regression-test/suites/table_sync_alias/column/drop_val/test_tsa_col_drop_val_col.groovy b/regression-test/suites/table_sync_alias/column/drop_val/test_tsa_col_drop_val_col.groovy new file mode 100644 index 00000000..c290d4c4 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/drop_val/test_tsa_col_drop_val_col.groovy @@ -0,0 +1,100 @@ +// 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_tsa_col_drop_val") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + def value_column_not_exists = { res -> Boolean + def not_exists = true + for (int i = 0; i < res.size(); i++) { + if (res[i][0] == 'value') { + not_exists = false + } + } + return not_exists + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT, + `value` INT + ) + ENGINE=OLAP + DUPLICATE KEY(`test`, `id`) + DISTRIBUTED BY HASH(test) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + logger.info("=== Test 1: add data and sync create ===") + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 2: drop value column ===") + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `value` + """ + + logger.info("=== Test 2: Check value column ===") + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", value_column_not_exists, 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", value_column_not_exists, 60, "target_sql")) +} + diff --git a/regression-test/suites/table_sync_alias/column/order_by/test_tsa_col_order_by.groovy b/regression-test/suites/table_sync_alias/column/order_by/test_tsa_col_order_by.groovy new file mode 100644 index 00000000..e5383eaa --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/order_by/test_tsa_col_order_by.groovy @@ -0,0 +1,94 @@ +// 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_tsa_col_order_by") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def key_columns_order = { res -> Boolean + return res[0][0] == 'id' && (res[0][3] == 'YES' || res[0][3] == 'true') && + res[1][0] == 'test' && (res[1][3] == 'YES' || res[1][3] == 'true') && + res[2][0] == 'value1' && (res[2][3] == 'NO' || res[2][3] == 'false') && + res[3][0] == 'value' && (res[3][3] == 'NO' || res[3][3] == 'false') + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `test` INT, + `id` INT, + `value` INT, + `value1` INT + ) + ENGINE=OLAP + UNIQUE KEY(`test`, `id`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + logger.info("=== Test 1: add data and sync create ===") + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 2: order by column case ===") + + sql """ + ALTER TABLE ${tableName} + ORDER BY (`id`, `test`, `value1`, `value`) + """ + + logger.info("=== Test 3: Check ordered column ===") + + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + exist, 30)) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", key_columns_order, 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", key_columns_order, 60, "target_sql")) +} + diff --git a/regression-test/suites/table_sync_alias/column/rename/test_tsa_col_rename.groovy b/regression-test/suites/table_sync_alias/column/rename/test_tsa_col_rename.groovy new file mode 100644 index 00000000..f98c8bc3 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rename/test_tsa_col_rename.groovy @@ -0,0 +1,125 @@ +// 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_tsa_col_rename") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "alias_tbl_" + helper.randomSuffix() + def newColName = 'test_tsa_col_rename_new_col' + def oldColName = 'test_tsa_col_rename_old_col' + def test_num = 0 + def insert_num = 5 + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + def has_column = { column -> + return { res -> Boolean + res[0][0] == column + } + } + + def not_has_column = { column -> + return { res -> Boolean + res[0][0] != column + } + } + + helper.enableDbBinlog() + sql "DROP TABLE IF EXISTS ${tableName}" + target_sql "DROP TABLE IF EXISTS ${aliasTableName}" + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + ${oldColName} INT, + `id` INT, + `value` INT + ) + ENGINE=OLAP + UNIQUE KEY(${oldColName}, `id`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + + def values = []; + for (int index = 0; index < insert_num; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + result = sql "select * from ${tableName}" + + assertEquals(result.size(), insert_num) + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + logger.info("=== Test 1: Check old column exist and new column not exist ===") + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", has_column(oldColName), 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", not_has_column(newColName), 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", has_column(oldColName), 60, "target_sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", not_has_column(newColName), 60, "target_sql")) + + logger.info("=== Test 2: Alter table rename column and insert data ===") + + sql "ALTER TABLE ${tableName} RENAME COLUMN ${oldColName} ${newColName} " + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", has_column(newColName), 60, "sql")) + + values = []; + for (int index = insert_num; index < insert_num * 2; index++) { + values.add("(${test_num}, ${index}, ${index})") + } + sql """ + INSERT INTO ${tableName} VALUES ${values.join(",")} + """ + + logger.info("=== Test 3: Check old column not exist and new column exist ===") + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", not_has_column(oldColName), 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${tableName}", has_column(newColName), 60, "sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", not_has_column(oldColName), 60, "target_sql")) + + assertTrue(helper.checkShowTimesOf("SHOW COLUMNS FROM ${aliasTableName}", has_column(newColName), 60, "target_sql")) + + logger.info("=== Test 4: Check inserted data ===") + + result = sql " select * from ${tableName} " + + result_target = target_sql " select * from ${aliasTableName} " + + assertEquals(result, result_target) + +} + diff --git a/regression-test/suites/table_sync_alias/column/rollup/add_drop/test_tsa_rollup_add_drop.groovy b/regression-test/suites/table_sync_alias/column/rollup/add_drop/test_tsa_rollup_add_drop.groovy new file mode 100644 index 00000000..0c723554 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rollup/add_drop/test_tsa_rollup_add_drop.groovy @@ -0,0 +1,120 @@ +// 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_tsa_rollup_add_drop') { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", 'helper.groovy')) + + if (helper.has_feature('feature_skip_rollup_binlogs')) { + logger.info('skip this suite because feature_skip_rollup_binlogs is enabled') + return + } + + def tableName = 'tbl_' + helper.randomSuffix() + def aliasTableName = 'tbl_alias_' + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_full (id, col2, col4) + """ + + def rollupFullFinished = { res -> Boolean + for (List row : res) { + if ((row[5] as String).contains("rollup_${tableName}_full")) { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + rollupFullFinished, 30)) + sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")""" + + logger.info('=== Test 1: full update rollup ===') + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + def hasRollupFull = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${aliasTableName} ALL", + hasRollupFull, 30, 'target')) + + logger.info('=== Test 2: incremental update rollup ===') + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_incr (id, col1, col3) + """ + def hasRollupIncremental = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_incr") { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${aliasTableName} ALL", + hasRollupIncremental, 30, 'target')) + + logger.info('=== Test 3: drop rollup') + sql """ + ALTER TABLE ${tableName} DROP ROLLUP rollup_${tableName}_incr + """ + + def hasRollupIncrementalDropped = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_incr") { + return false + } + } + return true + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${aliasTableName} ALL", + hasRollupIncrementalDropped, 30, 'target')) +} diff --git a/regression-test/suites/table_sync_alias/column/rollup/rename/test_tsa_rollup_rename.groovy b/regression-test/suites/table_sync_alias/column/rollup/rename/test_tsa_rollup_rename.groovy new file mode 100644 index 00000000..f9398fc7 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rollup/rename/test_tsa_rollup_rename.groovy @@ -0,0 +1,105 @@ +// 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_ds_rollup_rename") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + if (helper.has_feature("feature_skip_rollup_binlogs")) { + logger.info("skip this suite because feature_skip_rollup_binlogs is enabled") + return + } + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "tbl_alias_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName}_full (id, col2, col4) + """ + + def rollupFullFinished = { res -> Boolean + for (List row : res) { + if ((row[5] as String).contains("rollup_${tableName}_full")) { + return true + } + } + return false + } + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + rollupFullFinished, 30)) + sql """ALTER TABLE ${tableName} set ("binlog.enable" = "true")""" + + logger.info("=== Test 1: full update rollup ===") + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + + def hasRollupFull = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${aliasTableName} ALL", + hasRollupFull, 30, "target")) + + logger.info("=== Test 2: Rename rollup ===") + sql """ + ALTER TABLE ${tableName} + RENAME ROLLUP rollup_${tableName}_full rollup_${tableName}_full_new + """ + def hasRollupFullNew = { res -> Boolean + for (List row : res) { + if ((row[0] as String) == "rollup_${tableName}_full_new") { + return true + } + } + + return false + } + assertTrue(helper.checkShowTimesOf("DESC TEST_${context.dbName}.${aliasTableName} ALL", + hasRollupFullNew, 30, "target")) +} diff --git a/regression-test/suites/table_sync_alias/column/rollup_col/add/test_tsa_rollup_col_add.groovy b/regression-test/suites/table_sync_alias/column/rollup_col/add/test_tsa_rollup_col_add.groovy new file mode 100644 index 00000000..b9665d2a --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rollup_col/add/test_tsa_rollup_col_add.groovy @@ -0,0 +1,105 @@ +// 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_ds_rollup_col_add") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "tbl_alias_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: add key column ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `key` INT KEY DEFAULT "0" + TO rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 2: add value column ===") + sql """ + ALTER TABLE ${tableName} + ADD COLUMN `first_value` INT DEFAULT "0" + TO rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(2), 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) +} diff --git a/regression-test/suites/table_sync_alias/column/rollup_col/drop/test_tsa_rollup_col_drop.groovy b/regression-test/suites/table_sync_alias/column/rollup_col/drop/test_tsa_rollup_col_drop.groovy new file mode 100644 index 00000000..6cf353c3 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rollup_col/drop/test_tsa_rollup_col_drop.groovy @@ -0,0 +1,108 @@ +// 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_ds_rollup_col_drop") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "tbl_alias_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DUPLICATE KEY(`id`, `col1`, `col2`) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: drop key column ===") + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `col2` + FROM rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 2: drop value column ===") + + sql """ + ALTER TABLE ${tableName} + DROP COLUMN `col4` + FROM rollup_${tableName} + """ + sql "sync" + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(2), 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) +} diff --git a/regression-test/suites/table_sync_alias/column/rollup_col/order_by/test_tsa_rollup_col_order_by.groovy b/regression-test/suites/table_sync_alias/column/rollup_col/order_by/test_tsa_rollup_col_order_by.groovy new file mode 100644 index 00000000..7a6f08e3 --- /dev/null +++ b/regression-test/suites/table_sync_alias/column/rollup_col/order_by/test_tsa_rollup_col_order_by.groovy @@ -0,0 +1,89 @@ +// 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_ds_rollup_col_order_by") { + def helper = new GroovyShell(new Binding(['suite': delegate])) + .evaluate(new File("${context.config.suitePath}/../common", "helper.groovy")) + + def tableName = "tbl_" + helper.randomSuffix() + def aliasTableName = "tbl_alias_" + helper.randomSuffix() + def test_num = 0 + def insert_num = 5 + + helper.set_alias(aliasTableName) + + def exist = { res -> Boolean + return res.size() != 0 + } + + def has_count = { count -> + return { res -> Boolean + res.size() == count + } + } + + sql """ + CREATE TABLE if NOT EXISTS ${tableName} + ( + `id` INT, + `col1` INT, + `col2` INT, + `col3` INT, + `col4` INT, + ) + ENGINE=OLAP + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "binlog.enable" = "true" + ) + """ + sql """ + ALTER TABLE ${tableName} + ADD ROLLUP rollup_${tableName} (id, col2, col4) + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE ROLLUP + FROM ${context.dbName} + WHERE TableName = "${tableName}" AND State = "FINISHED" + """, + has_count(1), 30)) + + helper.ccrJobDelete(tableName) + helper.ccrJobCreate(tableName) + assertTrue(helper.checkRestoreFinishTimesOf("${tableName}", 30)) + assertTrue(helper.check_table_describe_times(tableName, 30)) + + logger.info("=== Test 1: order by columns ===") + sql """ + ALTER TABLE ${tableName} + ORDER BY (col2, id, col4) + FROM rollup_${tableName} + """ + + assertTrue(helper.checkShowTimesOf(""" + SHOW ALTER TABLE COLUMN + FROM ${context.dbName} + WHERE TableName = "${tableName}" + AND IndexName = "rollup_${tableName}" + AND State = "FINISHED" + """, + has_count(1), 30)) + + assertTrue(helper.check_table_describe_times(tableName, 30)) +} +