Skip to content

Commit ebdf147

Browse files
committed
add tests for replicated engine
1 parent b0c7e9e commit ebdf147

4 files changed

+76
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---- Export 2020_0_0_0 and 2021_0_0_0
2+
---- Both data parts should appear
3+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 1
4+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 2
5+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 3
6+
test/s3_table_NAME/year=2021/2021_0_0_0.parquet 4
7+
---- Export the same part again, it should be idempotent
8+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 1
9+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 2
10+
test/s3_table_NAME/year=2020/2020_0_0_0.parquet 3
11+
test/s3_table_NAME/year=2021/2021_0_0_0.parquet 4
12+
---- Data in roundtrip ReplicatedMergeTree table (should match s3_table)
13+
1 2020
14+
2 2020
15+
3 2020
16+
4 2021
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
# shellcheck source=../shell_config.sh
5+
. "$CURDIR"/../shell_config.sh
6+
7+
rmt_table="rmt_table_${RANDOM}"
8+
s3_table="s3_table_${RANDOM}"
9+
rmt_table_roundtrip="rmt_table_roundtrip_${RANDOM}"
10+
11+
query() {
12+
$CLICKHOUSE_CLIENT --query "$1"
13+
}
14+
15+
query "DROP TABLE IF EXISTS $rmt_table, $s3_table, $rmt_table_roundtrip"
16+
17+
query "CREATE TABLE $rmt_table (id UInt64, year UInt16) ENGINE = ReplicatedMergeTree('/clickhouse/tables/$CLICKHOUSE_TEST_UNIQUE_NAME/$rmt_table', 'replica1') PARTITION BY year ORDER BY tuple()"
18+
query "CREATE TABLE $s3_table (id UInt64, year UInt16) ENGINE = S3(s3_conn, filename='$s3_table', format=Parquet, partition_strategy='hive') PARTITION BY year"
19+
20+
query "INSERT INTO $rmt_table VALUES (1, 2020), (2, 2020), (3, 2020), (4, 2021)"
21+
echo "---- Export 2020_0_0_0 and 2021_0_0_0"
22+
query "ALTER TABLE $rmt_table EXPORT PART '2020_0_0_0' TO TABLE $s3_table SETTINGS allow_experimental_export_merge_tree_part = 1"
23+
query "ALTER TABLE $rmt_table EXPORT PART '2021_0_0_0' TO TABLE $s3_table SETTINGS allow_experimental_export_merge_tree_part = 1"
24+
25+
echo "---- Both data parts should appear"
26+
query "SELECT DISTINCT ON (id) replaceRegexpAll(_path, '$s3_table', 's3_table_NAME'), id FROM $s3_table ORDER BY id"
27+
28+
echo "---- Export the same part again, it should be idempotent"
29+
query "ALTER TABLE $rmt_table EXPORT PART '2020_0_0_0' TO TABLE $s3_table SETTINGS allow_experimental_export_merge_tree_part = 1"
30+
31+
query "SELECT DISTINCT ON (id) replaceRegexpAll(_path, '$s3_table', 's3_table_NAME'), id FROM $s3_table ORDER BY id"
32+
33+
query "CREATE TABLE $rmt_table_roundtrip ENGINE = ReplicatedMergeTree('/clickhouse/tables/$CLICKHOUSE_TEST_UNIQUE_NAME/$rmt_table_roundtrip', 'replica1') PARTITION BY year ORDER BY tuple() AS SELECT * FROM $s3_table"
34+
35+
echo "---- Data in roundtrip ReplicatedMergeTree table (should match s3_table)"
36+
query "SELECT DISTINCT ON (id) * FROM $rmt_table_roundtrip ORDER BY id"
37+
38+
query "DROP TABLE IF EXISTS $rmt_table, $s3_table, $rmt_table_roundtrip"

tests/queries/0_stateless/03572_export_replicated_merge_tree_part_to_object_storage_simple.reference

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Tags: no-parallel
2+
3+
DROP TABLE IF EXISTS 03572_rmt_table, 03572_invalid_schema_table;
4+
5+
CREATE TABLE 03572_rmt_table (id UInt64, year UInt16) ENGINE = ReplicatedMergeTree('/clickhouse/{database}/test_03572_rmt/03572_rmt_table', 'replica1') PARTITION BY year ORDER BY tuple();
6+
7+
INSERT INTO 03572_rmt_table VALUES (1, 2020);
8+
9+
-- Create a table with a different partition key and export a partition to it. It should throw
10+
CREATE TABLE 03572_invalid_schema_table (id UInt64, x UInt16) ENGINE = S3(s3_conn, filename='03572_invalid_schema_table', format='Parquet', partition_strategy='hive') PARTITION BY x;
11+
12+
ALTER TABLE 03572_rmt_table EXPORT PART '2020_0_0_0' TO TABLE 03572_invalid_schema_table
13+
SETTINGS allow_experimental_export_merge_tree_part = 1; -- {serverError INCOMPATIBLE_COLUMNS}
14+
15+
DROP TABLE 03572_invalid_schema_table;
16+
17+
-- The only partition strategy that supports exports is hive. Wildcard should throw
18+
CREATE TABLE 03572_invalid_schema_table (id UInt64, year UInt16) ENGINE = S3(s3_conn, filename='03572_invalid_schema_table/{_partition_id}', format='Parquet', partition_strategy='wildcard') PARTITION BY (id, year);
19+
20+
ALTER TABLE 03572_rmt_table EXPORT PART '2020_0_0_0' TO TABLE 03572_invalid_schema_table SETTINGS allow_experimental_export_merge_tree_part = 1; -- {serverError NOT_IMPLEMENTED}
21+
22+
DROP TABLE IF EXISTS 03572_rmt_table, 03572_invalid_schema_table;

0 commit comments

Comments
 (0)