Add stateless test for CREATE with CLONE AS

This commit is contained in:
Tuan Pham Anh 2024-08-30 08:12:25 +00:00
parent 14a968b08a
commit 809a739636
3 changed files with 65 additions and 2 deletions

View File

@ -830,7 +830,7 @@ InterpreterCreateQuery::TableProperties InterpreterCreateQuery::getTableProperti
properties.columns.resetColumnTTLs();
if (create.is_clone_as)
{
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Only support 'CLONE AS' with tables of MergeTree family");
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Only support CLONE AS with tables of the MergeTree family");
}
}
@ -1939,7 +1939,7 @@ BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create)
/* async_isnert */ false).execute();
}
/// If the query is a CREATE .. CLONE AS <table>, insert the data into the table.
/// If the query is a CREATE TABLE .. CLONE AS ..., attach all partitions of the source table to the newly created table.
if (create.is_clone_as && !as_table_saved.empty() && !create.is_create_empty && !create.is_ordinary_view && !create.is_live_view
&& (!(create.is_materialized_view || create.is_window_view) || create.is_populate))
{

View File

@ -0,0 +1,8 @@
1
1
CREATE TABLE default.clone_as_foo_merge_tree\n(\n `x` Int8\n)\nENGINE = MergeTree\nPRIMARY KEY x\nORDER BY x\nSETTINGS index_granularity = 8192
1
2
CREATE TABLE default.clone_as_foo_replacing_merge_tree\n(\n `x` Int8\n)\nENGINE = ReplacingMergeTree\nPRIMARY KEY x\nORDER BY x\nSETTINGS index_granularity = 8192
1
2

View File

@ -0,0 +1,55 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
clickhouse-client -q "DROP TABLE IF EXISTS foo_memory"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_memory"
clickhouse-client -q "DROP TABLE IF EXISTS foo_file"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_file"
clickhouse-client -q "DROP TABLE IF EXISTS foo_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS foo_replacing_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_replacing_merge_tree"
# CLONE AS with a table of Memory engine
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE foo_memory (x Int8) ENGINE=Memory"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="INSERT INTO foo_memory VALUES (1), (2)"
echo "$(${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --server_logs_file=/dev/null --query="CREATE TABLE clone_as_foo_memory CLONE AS foo_memory" 2>&1)" \
| grep -c 'Code: 344. DB::Exception: .* Only support CLONE AS with tables of the MergeTree family'
# CLONE AS with a table of File engine
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE foo_file (x Int8) ENGINE=File(TabSeparated)"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="INSERT INTO foo_file VALUES (1), (2)"
echo "$(${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --server_logs_file=/dev/null --query="CREATE TABLE clone_as_foo_file CLONE AS foo_file" 2>&1)" \
| grep -c 'Code: 344. DB::Exception: .* Only support CLONE AS with tables of the MergeTree family'
# CLONE AS with a table of MergeTree engine
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE foo_merge_tree (x Int8) ENGINE=MergeTree PRIMARY KEY x"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="INSERT INTO foo_merge_tree VALUES (1), (2)"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE clone_as_foo_merge_tree CLONE AS foo_merge_tree"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="SHOW CREATE TABLE clone_as_foo_merge_tree"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="SELECT * FROM foo_merge_tree"
# CLONE AS with a table of ReplacingMergeTree engine
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE foo_replacing_merge_tree (x Int8) ENGINE=ReplacingMergeTree PRIMARY KEY x"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="INSERT INTO foo_replacing_merge_tree VALUES (1), (2)"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="CREATE TABLE clone_as_foo_replacing_merge_tree CLONE AS foo_replacing_merge_tree"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="SHOW CREATE TABLE clone_as_foo_replacing_merge_tree"
${CLICKHOUSE_CLIENT} --optimize_throw_if_noop 1 --query="SELECT * FROM clone_as_foo_replacing_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS foo_memory"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_memory"
clickhouse-client -q "DROP TABLE IF EXISTS foo_file"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_file"
clickhouse-client -q "DROP TABLE IF EXISTS foo_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS foo_replacing_merge_tree"
clickhouse-client -q "DROP TABLE IF EXISTS clone_as_foo_replacing_merge_tree"