|
| 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" |
0 commit comments