From 96f558f51ae014db0ab0cd6fe91cc2b93732c4e5 Mon Sep 17 00:00:00 2001 From: Nikolay Degterinsky Date: Thu, 9 Nov 2023 06:19:00 +0000 Subject: [PATCH] Fix ALTER COMMENT queries ON CLUSTER --- src/Interpreters/DDLWorker.cpp | 3 +- src/Parsers/ASTAlterQuery.cpp | 5 ++ src/Parsers/ASTAlterQuery.h | 2 + .../test_alter_comment_on_cluster/__init__.py | 0 .../configs/clusters.xml | 16 +++++ .../test_alter_comment_on_cluster/test.py | 61 +++++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/integration/test_alter_comment_on_cluster/__init__.py create mode 100644 tests/integration/test_alter_comment_on_cluster/configs/clusters.xml create mode 100644 tests/integration/test_alter_comment_on_cluster/test.py diff --git a/src/Interpreters/DDLWorker.cpp b/src/Interpreters/DDLWorker.cpp index da46aad0329..61a6a0335f7 100644 --- a/src/Interpreters/DDLWorker.cpp +++ b/src/Interpreters/DDLWorker.cpp @@ -725,7 +725,8 @@ bool DDLWorker::taskShouldBeExecutedOnLeader(const ASTPtr & ast_ddl, const Stora // Setting alters should be executed on all replicas if (alter->isSettingsAlter() || alter->isFreezeAlter() || - alter->isMovePartitionToDiskOrVolumeAlter()) + alter->isMovePartitionToDiskOrVolumeAlter() || + alter->isCommentAlter()) return false; } diff --git a/src/Parsers/ASTAlterQuery.cpp b/src/Parsers/ASTAlterQuery.cpp index 955320c318c..aba6803a8ab 100644 --- a/src/Parsers/ASTAlterQuery.cpp +++ b/src/Parsers/ASTAlterQuery.cpp @@ -486,6 +486,11 @@ bool ASTAlterQuery::isDropPartitionAlter() const return isOneCommandTypeOnly(ASTAlterCommand::DROP_PARTITION) || isOneCommandTypeOnly(ASTAlterCommand::DROP_DETACHED_PARTITION); } +bool ASTAlterQuery::isCommentAlter() const +{ + return isOneCommandTypeOnly(ASTAlterCommand::COMMENT_COLUMN) || isOneCommandTypeOnly(ASTAlterCommand::MODIFY_COMMENT); +} + bool ASTAlterQuery::isMovePartitionToDiskOrVolumeAlter() const { if (command_list) diff --git a/src/Parsers/ASTAlterQuery.h b/src/Parsers/ASTAlterQuery.h index 30cf0cac4ce..f8e3fb96dd3 100644 --- a/src/Parsers/ASTAlterQuery.h +++ b/src/Parsers/ASTAlterQuery.h @@ -239,6 +239,8 @@ public: bool isMovePartitionToDiskOrVolumeAlter() const; + bool isCommentAlter() const; + String getID(char) const override; ASTPtr clone() const override; diff --git a/tests/integration/test_alter_comment_on_cluster/__init__.py b/tests/integration/test_alter_comment_on_cluster/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_alter_comment_on_cluster/configs/clusters.xml b/tests/integration/test_alter_comment_on_cluster/configs/clusters.xml new file mode 100644 index 00000000000..d5293291c18 --- /dev/null +++ b/tests/integration/test_alter_comment_on_cluster/configs/clusters.xml @@ -0,0 +1,16 @@ + + + + + + node_1 + 9000 + + + node_2 + 9000 + + + + + \ No newline at end of file diff --git a/tests/integration/test_alter_comment_on_cluster/test.py b/tests/integration/test_alter_comment_on_cluster/test.py new file mode 100644 index 00000000000..e6767e35c1b --- /dev/null +++ b/tests/integration/test_alter_comment_on_cluster/test.py @@ -0,0 +1,61 @@ +import pytest +from helpers.cluster import ClickHouseCluster +from helpers.test_tools import assert_eq_with_retry + +cluster = ClickHouseCluster(__file__) + +node_1 = cluster.add_instance( + "node_1", + main_configs=["configs/clusters.xml"], + with_zookeeper=True, + macros={"shard": 1, "replica": 1}, +) + +node_2 = cluster.add_instance( + "node_2", + main_configs=["configs/clusters.xml"], + with_zookeeper=True, + macros={"shard": 1, "replica": 2}, +) + + +def assert_create_query(nodes, database_name, table_name, expected): + query = "SELECT create_table_query FROM system.tables WHERE database='{}' AND table='{}'".format( + database_name, table_name + ) + for node in nodes: + assert_eq_with_retry(node, query, expected) + + +@pytest.fixture(scope="module") +def started_cluster(): + try: + cluster.start() + yield cluster + finally: + cluster.shutdown() + + +def test_comment(started_cluster): + node_1.query( + "CREATE TABLE test_table ON CLUSTER 'cluster' (id Int64) ENGINE=ReplicatedMergeTree() ORDER BY id" + ) + node_1.query( + "ALTER TABLE test_table ON CLUSTER 'cluster' COMMENT COLUMN id 'column_comment_1'" + ) + node_1.query( + "ALTER TABLE test_table ON CLUSTER 'cluster' MODIFY COMMENT 'table_comment_1';" + ) + + expected = "CREATE TABLE default.test_table (`id` Int64 COMMENT \\'column_comment_1\\') ENGINE = ReplicatedMergeTree(\\'/clickhouse/tables/{uuid}/{shard}\\', \\'{replica}\\') ORDER BY id SETTINGS index_granularity = 8192 COMMENT \\'table_comment_1\\'" + assert_create_query([node_1, node_2], "default", "test_table", expected) + + node_1.query( + "ALTER TABLE test_table ON CLUSTER 'cluster' COMMENT COLUMN id 'column_comment_2'" + ) + node_1.query( + "ALTER TABLE test_table ON CLUSTER 'cluster' MODIFY COMMENT 'table_comment_2';" + ) + + expected = "CREATE TABLE default.test_table (`id` Int64 COMMENT \\'column_comment_2\\') ENGINE = ReplicatedMergeTree(\\'/clickhouse/tables/{uuid}/{shard}\\', \\'{replica}\\') ORDER BY id SETTINGS index_granularity = 8192 COMMENT \\'table_comment_2\\'" + assert_create_query([node_1, node_2], "default", "test_table", expected)