From 97d437f70456bc28ff5bcf7a133ade54f8ff35d2 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Fri, 22 Nov 2024 11:04:52 +0800 Subject: [PATCH] dumpling: add partition table test cases --- .../tests/partition_table/data/pt_case_0.sql | 13 +++++++++ .../tests/partition_table/data/pt_case_1.sql | 16 +++++++++++ .../result/pt_case_0-schema.sql | 8 ++++++ .../partition_table/result/pt_case_0.sql | 14 ++++++++++ .../result/pt_case_1-schema.sql | 11 ++++++++ .../partition_table/result/pt_case_1.sql | 14 ++++++++++ dumpling/tests/partition_table/run.sh | 27 +++++++++++++++++++ 7 files changed, 103 insertions(+) create mode 100644 dumpling/tests/partition_table/data/pt_case_0.sql create mode 100644 dumpling/tests/partition_table/data/pt_case_1.sql create mode 100644 dumpling/tests/partition_table/result/pt_case_0-schema.sql create mode 100644 dumpling/tests/partition_table/result/pt_case_0.sql create mode 100644 dumpling/tests/partition_table/result/pt_case_1-schema.sql create mode 100644 dumpling/tests/partition_table/result/pt_case_1.sql create mode 100644 dumpling/tests/partition_table/run.sh diff --git a/dumpling/tests/partition_table/data/pt_case_0.sql b/dumpling/tests/partition_table/data/pt_case_0.sql new file mode 100644 index 0000000000000..caa6890a93047 --- /dev/null +++ b/dumpling/tests/partition_table/data/pt_case_0.sql @@ -0,0 +1,13 @@ +create table `pt_case_0` (a int, b int, unique index idx(a) global) partition by hash(b) partitions 5; +insert into `pt_case_0` values +(0, 10), +(1, 9), +(2, 8), +(3, 7), +(4, 6), +(5, 5), +(6, 4), +(7, 3), +(8, 2), +(9, 1), +(10, 0); diff --git a/dumpling/tests/partition_table/data/pt_case_1.sql b/dumpling/tests/partition_table/data/pt_case_1.sql new file mode 100644 index 0000000000000..dacd1b37d117b --- /dev/null +++ b/dumpling/tests/partition_table/data/pt_case_1.sql @@ -0,0 +1,16 @@ +create table `pt_case_1` (a int, b int, unique index idx(a) global) partition by list(b) +(partition p0 values in (0, 1, 2, 3), + partition p1 values in (4, 5, 6), + partition p2 values in (7, 8, 9, 10)); +insert into `pt_case_1` values +(0, 10), +(1, 9), +(2, 8), +(3, 7), +(4, 6), +(5, 5), +(6, 4), +(7, 3), +(8, 2), +(9, 1), +(10, 0); diff --git a/dumpling/tests/partition_table/result/pt_case_0-schema.sql b/dumpling/tests/partition_table/result/pt_case_0-schema.sql new file mode 100644 index 0000000000000..ac2691edc5492 --- /dev/null +++ b/dumpling/tests/partition_table/result/pt_case_0-schema.sql @@ -0,0 +1,8 @@ +/*!40014 SET FOREIGN_KEY_CHECKS=0*/; +/*!40101 SET NAMES binary*/; +CREATE TABLE `pt_case_0` ( + `a` int DEFAULT NULL, + `b` int DEFAULT NULL, + UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY HASH (`b`) PARTITIONS 5; diff --git a/dumpling/tests/partition_table/result/pt_case_0.sql b/dumpling/tests/partition_table/result/pt_case_0.sql new file mode 100644 index 0000000000000..124393a91551e --- /dev/null +++ b/dumpling/tests/partition_table/result/pt_case_0.sql @@ -0,0 +1,14 @@ +/*!40014 SET FOREIGN_KEY_CHECKS=0*/; +/*!40101 SET NAMES binary*/; +INSERT INTO `pt_case_0` VALUES +(0,10), +(1,9), +(2,8), +(3,7), +(4,6), +(5,5), +(6,4), +(7,3), +(8,2), +(9,1), +(10,0); diff --git a/dumpling/tests/partition_table/result/pt_case_1-schema.sql b/dumpling/tests/partition_table/result/pt_case_1-schema.sql new file mode 100644 index 0000000000000..b3e5510c5eabb --- /dev/null +++ b/dumpling/tests/partition_table/result/pt_case_1-schema.sql @@ -0,0 +1,11 @@ +/*!40014 SET FOREIGN_KEY_CHECKS=0*/; +/*!40101 SET NAMES binary*/; +CREATE TABLE `pt_case_1` ( + `a` int DEFAULT NULL, + `b` int DEFAULT NULL, + UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST (`b`) +(PARTITION `p0` VALUES IN (0,1,2,3), + PARTITION `p1` VALUES IN (4,5,6), + PARTITION `p2` VALUES IN (7,8,9,10)); diff --git a/dumpling/tests/partition_table/result/pt_case_1.sql b/dumpling/tests/partition_table/result/pt_case_1.sql new file mode 100644 index 0000000000000..dbdb0033d0929 --- /dev/null +++ b/dumpling/tests/partition_table/result/pt_case_1.sql @@ -0,0 +1,14 @@ +/*!40014 SET FOREIGN_KEY_CHECKS=0*/; +/*!40101 SET NAMES binary*/; +INSERT INTO `pt_case_1` VALUES +(0,10), +(1,9), +(2,8), +(3,7), +(4,6), +(5,5), +(6,4), +(7,3), +(8,2), +(9,1), +(10,0); diff --git a/dumpling/tests/partition_table/run.sh b/dumpling/tests/partition_table/run.sh new file mode 100644 index 0000000000000..2ec3476dacfbe --- /dev/null +++ b/dumpling/tests/partition_table/run.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. + +set -eu + +export DUMPLING_TEST_PORT=4000 + +run_sql "drop database if exists partition_table" +run_sql "create database partition_table DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" +export DUMPLING_TEST_DATABASE=partition_table + +for data in "$DUMPLING_BASE_NAME"/data/*; do + run_sql_file "$data" +done + +run_dumpling + +for file_path in "$DUMPLING_BASE_NAME"/data/*; do + base_name=$(basename "$file_path") + table_name="${base_name%.sql}" + file_should_exist "$DUMPLING_BASE_NAME/result/$table_name.sql" + file_should_exist "$DUMPLING_OUTPUT_DIR/partition_table.$table_name.000000000.sql" + file_should_exist "$DUMPLING_OUTPUT_DIR/partition_table.$table_name-schema.sql" + diff "$DUMPLING_BASE_NAME/result/$table_name.sql" "$DUMPLING_OUTPUT_DIR/partition_table.$table_name.000000000.sql" + diff "$DUMPLING_BASE_NAME/result/$table_name-schema.sql" "$DUMPLING_OUTPUT_DIR/partition_table.$table_name-schema.sql" +done