forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ClickHouse#57111 from ClickHouse/backport/23.8/56484
Backport ClickHouse#56484 to 23.8: Fix ON CLUSTER queries without database on initial node
- Loading branch information
Showing
5 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
12 changes: 12 additions & 0 deletions
12
tests/integration/test_external_cluster/configs/clusters.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<clickhouse> | ||
<remote_servers> | ||
<external> | ||
<shard> | ||
<replica> | ||
<host>data_node</host> | ||
<port>9000</port> | ||
</replica> | ||
</shard> | ||
</external> | ||
</remote_servers> | ||
</clickhouse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import re | ||
import pytest | ||
from helpers.cluster import ClickHouseCluster | ||
from helpers.test_tools import assert_eq_with_retry | ||
|
||
cluster = ClickHouseCluster(__file__) | ||
|
||
control_node = cluster.add_instance( | ||
"control_node", | ||
main_configs=["configs/clusters.xml"], | ||
with_zookeeper=True, | ||
) | ||
|
||
data_node = cluster.add_instance( | ||
"data_node", | ||
main_configs=["configs/clusters.xml"], | ||
with_zookeeper=True, | ||
macros={"shard": 1, "replica": 1}, | ||
) | ||
|
||
uuid_regex = re.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") | ||
|
||
|
||
def assert_create_query(node, database_name, table_name, expected): | ||
replace_uuid = lambda x: re.sub(uuid_regex, "uuid", x) | ||
query = "SELECT create_table_query FROM system.tables WHERE database='{}' AND table='{}'".format( | ||
database_name, table_name | ||
) | ||
assert_eq_with_retry(node, query, expected, get_result=replace_uuid) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def started_cluster(): | ||
try: | ||
cluster.start() | ||
yield cluster | ||
finally: | ||
cluster.shutdown() | ||
|
||
|
||
def test_ddl(started_cluster): | ||
control_node.query("CREATE DATABASE test_db ON CLUSTER 'external' ENGINE=Atomic") | ||
control_node.query( | ||
"CREATE TABLE test_db.test_table ON CLUSTER 'external' (id Int64) Engine=MergeTree ORDER BY id" | ||
) | ||
control_node.query( | ||
"ALTER TABLE test_db.test_table ON CLUSTER 'external' add column data String" | ||
) | ||
|
||
expected = "CREATE TABLE test_db.test_table (`id` Int64, `data` String) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 8192" | ||
assert_create_query(data_node, "test_db", "test_table", expected) | ||
|
||
control_node.query("DROP TABLE test_db.test_table ON CLUSTER 'external'") | ||
control_node.query("DROP DATABASE test_db ON CLUSTER 'external'") | ||
|
||
expected = "" | ||
assert_create_query(data_node, "test_db", "test_table", expected) | ||
|
||
|
||
def test_ddl_replicated(started_cluster): | ||
control_node.query( | ||
"CREATE DATABASE test_db ON CLUSTER 'external' ENGINE=Replicated('/replicated')", | ||
settings={"allow_experimental_database_replicated": 1}, | ||
) | ||
# Exception is expected | ||
assert "It's not initial query" in control_node.query_and_get_error( | ||
"CREATE TABLE test_db.test_table ON CLUSTER 'external' (id Int64) Engine=MergeTree ORDER BY id" | ||
) | ||
control_node.query("DROP DATABASE test_db ON CLUSTER 'external'") |