From e7c5991b39db0ea88842b1c58cef3b42c771fb0e Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Wed, 14 Jun 2023 13:19:26 +0200 Subject: [PATCH] MaterializedMySQL: Keep parenthesises for empty table overrides Empty table overrides are formatted without any parenthesises, but they are required by a parser, and it is not possible to parse empty table overrides without it. :) CREATE DATABASE db ... TABLE OVERRIDE t1() CREATE DATABASE db ... TABLE OVERRIDE `t1` This query will be saved to metadata and ClickHouse will not be able to start up, since table overrides require (). --- src/Parsers/ASTTableOverrides.cpp | 2 -- src/Parsers/tests/gtest_Parser.cpp | 2 +- .../materialize_with_ddl.py | 12 ++++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Parsers/ASTTableOverrides.cpp b/src/Parsers/ASTTableOverrides.cpp index af846a5dd43..ccb485f6c69 100644 --- a/src/Parsers/ASTTableOverrides.cpp +++ b/src/Parsers/ASTTableOverrides.cpp @@ -36,8 +36,6 @@ void ASTTableOverride::formatImpl(const FormatSettings & settings_, FormatState settings.ostr << hl_keyword << "TABLE OVERRIDE " << hl_none; ASTIdentifier(table_name).formatImpl(settings, state, frame); } - if (!columns && (!storage || storage->children.empty())) - return; auto override_frame = frame; if (is_standalone) { diff --git a/src/Parsers/tests/gtest_Parser.cpp b/src/Parsers/tests/gtest_Parser.cpp index 19872c4189a..2795de64b1d 100644 --- a/src/Parsers/tests/gtest_Parser.cpp +++ b/src/Parsers/tests/gtest_Parser.cpp @@ -215,7 +215,7 @@ INSTANTIATE_TEST_SUITE_P(ParserCreateDatabaseQuery, ParserTest, }, { "CREATE DATABASE db ENGINE=Foo TABLE OVERRIDE `tbl` (), TABLE OVERRIDE a (COLUMNS (_created DateTime MATERIALIZED now())), TABLE OVERRIDE b (PARTITION BY rand())", - "CREATE DATABASE db\nENGINE = Foo\nTABLE OVERRIDE `tbl`,\nTABLE OVERRIDE `a`\n(\n COLUMNS\n (\n `_created` DateTime MATERIALIZED now()\n )\n),\nTABLE OVERRIDE `b`\n(\n PARTITION BY rand()\n)" + "CREATE DATABASE db\nENGINE = Foo\nTABLE OVERRIDE `tbl`\n(\n\n),\nTABLE OVERRIDE `a`\n(\n COLUMNS\n (\n `_created` DateTime MATERIALIZED now()\n )\n),\nTABLE OVERRIDE `b`\n(\n PARTITION BY rand()\n)" }, { "CREATE DATABASE db ENGINE=MaterializeMySQL('addr:port', 'db', 'user', 'pw') TABLE OVERRIDE tbl (COLUMNS (id UUID) PARTITION BY toYYYYMM(created))", diff --git a/tests/integration/test_materialized_mysql_database/materialize_with_ddl.py b/tests/integration/test_materialized_mysql_database/materialize_with_ddl.py index f5c28832f79..5e846b6d907 100644 --- a/tests/integration/test_materialized_mysql_database/materialize_with_ddl.py +++ b/tests/integration/test_materialized_mysql_database/materialize_with_ddl.py @@ -2031,6 +2031,18 @@ def table_overrides(clickhouse_node, mysql_node, service_name): f"{explain_with_table_func} {testcase[0]}" ) + clickhouse_node.query("DROP DATABASE IF EXISTS table_overrides") + # Check empty table overrides + clickhouse_node.query( + f""" + CREATE DATABASE table_overrides ENGINE=MaterializeMySQL('{service_name}:3306', 'table_overrides', 'root', 'clickhouse') + TABLE OVERRIDE t1 () + """ + ) + check_query(clickhouse_node, "SELECT count() FROM table_overrides.t1", "1001\n") + show_db = clickhouse_node.query("SHOW CREATE DATABASE table_overrides") + assert "TABLE OVERRIDE `t1`\\n(\\n\\n)" in show_db, show_db + clickhouse_node.query("DROP DATABASE IF EXISTS table_overrides") mysql_node.query("DROP DATABASE IF EXISTS table_overrides")