ClickHouse/tests/queries/0_stateless/02990_rmt_replica_path_uuid.sql
Azat Khuzhin 58e5d7876b Allow uuid in replica_path if CREATE TABLE explicitly has it
Right now the query with {uuid} macro without ON CLUSTER fails:

    CREATE TABLE x UUID 'aaaaaaaa-1111-2222-3333-aaaaaaaaaaaa' (key Int) ENGINE = ReplicatedMergeTree('/tables/{database}/{uuid}', 'r1') ORDER BY tuple();

There is a workaround right now to use ATTACH instead of CREATE, but
ATTACH is not CREATE.

CREATE still useful for proper RESTORE without ON CLUSTER.

So this patch allows this syntax, but only if UUID had been explicitly
passed in the query. This looks safe.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2024-02-13 08:01:09 +01:00

24 lines
1.2 KiB
SQL

-- Tags: no-parallel, no-ordinary-database, no-replicated-database
-- Tag no-parallel: static UUID
-- Tag no-ordinary-database: requires UUID
-- Tag no-replicated-database: executes with ON CLUSTER anyway
-- Ignore "ATTACH TABLE query with full table definition is not recommended"
-- Ignore BAD_ARGUMENTS
SET send_logs_level='fatal';
DROP TABLE IF EXISTS x;
ATTACH TABLE x UUID 'aaaaaaaa-1111-2222-3333-aaaaaaaaaaaa' (key Int) ENGINE = ReplicatedMergeTree('/tables/{database}/{uuid}', 'r1') ORDER BY tuple();
SELECT uuid FROM system.tables WHERE database = currentDatabase() and table = 'x';
SELECT replica_path FROM system.replicas WHERE database = currentDatabase() and table = 'x';
DROP TABLE x;
-- {uuid} macro forbidden for CREATE TABLE without explicit UUID
CREATE TABLE x (key Int) ENGINE = ReplicatedMergeTree('/tables/{database}/{uuid}', 'r1') ORDER BY tuple(); -- { serverError BAD_ARGUMENTS }
CREATE TABLE x UUID 'aaaaaaaa-1111-2222-3333-aaaaaaaaaaaa' (key Int) ENGINE = ReplicatedMergeTree('/tables/{database}/{uuid}', 'r1') ORDER BY tuple();
SELECT uuid FROM system.tables WHERE database = currentDatabase() and table = 'x';
SELECT replica_path FROM system.replicas WHERE database = currentDatabase() and table = 'x';
DROP TABLE x;