Reject CREATE TABLE ... CLONE AS SELECT / table function · ClickHouse/ClickHouse@ae90c08 · GitHub
Skip to content

Commit ae90c08

Browse files
committed
Reject CREATE TABLE ... CLONE AS SELECT / table function
The parser accepted CREATE TABLE t CLONE AS SELECT ... and CREATE TABLE t CLONE AS <table_function>, but neither shape has partitions to attach, so the CLONE keyword was silently ignored and the table was created as a plain CREATE ... AS SELECT. Reject these shapes early in getTablePropertiesAndNormalizeCreateQuery with BAD_ARGUMENTS instead. Also fix ASTCreateQuery::formatQueryImpl: the `if (select)` branch did not emit CLONE, so an AST round-trip silently dropped the keyword. Add add_clone_if_needed alongside the existing add_empty_if_needed call so CLONE survives reformatting. After this, the randomized-settings injection in clickhouse-test round-trips CLONE faithfully and the interpreter check above catches the rewritten query. Fixes #104994
1 parent c1ccce2 commit ae90c08

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/Interpreters/InterpreterCreateQuery.cpp

Lines changed: 7 additions & 0 deletions

src/Parsers/ASTCreateQuery.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@ void ASTCreateQuery::formatQueryImpl(WriteBuffer & ostr, const FormatSettings &
593593
ostr << " POPULATE";
594594

595595
add_empty_if_needed();
596+
/// Mirrors `add_empty_if_needed` above: the `if (!as_table.empty())` and `if (as_table_function)`
597+
/// branches earlier consume CLONE for the table / table-function shapes; this call covers the
598+
/// `CLONE AS SELECT` shape so the keyword survives an AST format round-trip. The interpreter
599+
/// still rejects `CLONE AS SELECT` at execution, but the formatter must not silently drop CLONE.
600+
add_clone_if_needed();
596601

597602
if (sql_security && supportSQLSecurity() && sql_security->as<ASTSQLSecurity &>().type.has_value())
598603
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2
3+
3
Lines changed: 33 additions & 0 deletions

0 commit comments

Comments
 (0)