Skip to content

Commit

Permalink
dumpling: add partition table test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Nov 22, 2024
1 parent d42a36d commit 97d437f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dumpling/tests/partition_table/data/pt_case_0.sql
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 16 additions & 0 deletions dumpling/tests/partition_table/data/pt_case_1.sql
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 8 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_0-schema.sql
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_0.sql
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 11 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_1-schema.sql
Original file line number Diff line number Diff line change
@@ -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));
14 changes: 14 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_1.sql
Original file line number Diff line number Diff line change
@@ -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);
27 changes: 27 additions & 0 deletions dumpling/tests/partition_table/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97d437f

Please sign in to comment.