From df504df47519bbd602985bcdec10af5cd6f0be63 Mon Sep 17 00:00:00 2001 From: Guangdong Liu Date: Wed, 24 Jan 2024 17:15:07 +0800 Subject: [PATCH] [regression test](schema change) add case for partition (#30195) --- .../data/schema_change_p0/test_partition.out | 14 ++++ .../schema_change_p0/test_partition.groovy | 68 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 regression-test/data/schema_change_p0/test_partition.out create mode 100644 regression-test/suites/schema_change_p0/test_partition.groovy diff --git a/regression-test/data/schema_change_p0/test_partition.out b/regression-test/data/schema_change_p0/test_partition.out new file mode 100644 index 0000000000..a661aa01d2 --- /dev/null +++ b/regression-test/data/schema_change_p0/test_partition.out @@ -0,0 +1,14 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +1 1 xxx 1 +2 1 yyy 1 + +-- !sql_1 -- +1 1 xxx 1 +2 1 yyy 1 +3 1 xxx 1 + +-- !sql_2 -- +1 1 xxx 1 +2 1 yyy 1 + diff --git a/regression-test/suites/schema_change_p0/test_partition.groovy b/regression-test/suites/schema_change_p0/test_partition.groovy new file mode 100644 index 0000000000..d3d00d9fee --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_partition.groovy @@ -0,0 +1,68 @@ +// 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_partition") { + + def checkPartition = {tblName -> + def results = sql """SHOW PARTITIONS FROM ${tblName};""" + for (def result : results) { + logger.info("result:${result}") + if (["old_p1", "old_p2", "new_p1", "new_p2"].contains(result[1])) { + continue; + } + assertTrue(false); + } + } + + String tblName = "test_partition" + sql """DROP TABLE IF EXISTS ${tblName} FORCE; """ + + sql """ + CREATE TABLE `${tblName}` + ( + `siteid` INT DEFAULT '10', + `citycode` SMALLINT, + `username` VARCHAR(32) DEFAULT 'test', + `pv` BIGINT SUM DEFAULT '0' + ) + AGGREGATE KEY(`siteid`, `citycode`, `username`) + PARTITION BY RANGE(`siteid`) + ( + partition `old_p1` values [("1"), ("2")), + partition `old_p2` values [("2"), ("3")) + ) + DISTRIBUTED BY HASH(siteid) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ); + """ + + sql """INSERT INTO ${tblName}(siteid, citycode, username, pv) VALUES (1, 1, "xxx", 1), (2, 1, "yyy", 1);""" + sql """SYNC;""" + order_qt_sql """SELECT * from ${tblName};""" + + // add partition + sql """ALTER TABLE ${tblName} add PARTITION new_p1 values [("3"), ("4"));""" + sql """INSERT INTO ${tblName}(siteid, citycode, username, pv) VALUES (3, 1, "xxx", 1);""" + order_qt_sql_1 """SELECT * from ${tblName};""" + checkPartition(tblName); + // del partition + sql """ALTER TABLE ${tblName} DROP PARTITION new_p1;""" + order_qt_sql_2 """SELECT * from ${tblName};""" + checkPartition(tblName); + sql """DROP TABLE IF EXISTS ${tblName} FORCE; """ +}