2019-12-12 10:27:02 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.client import QueryRuntimeException
|
2020-09-16 04:26:10 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2019-12-12 10:27:02 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2020-09-16 04:26:10 +00:00
|
|
|
ch1 = cluster.add_instance('ch1', main_configs=["configs/config.d/clusters.xml", "configs/config.d/ddl.xml"],
|
|
|
|
with_zookeeper=True)
|
|
|
|
ch2 = cluster.add_instance('ch2', main_configs=["configs/config.d/clusters.xml", "configs/config.d/ddl.xml"],
|
|
|
|
with_zookeeper=True)
|
|
|
|
ch3 = cluster.add_instance('ch3', main_configs=["configs/config.d/clusters.xml", "configs/config.d/ddl.xml"],
|
|
|
|
with_zookeeper=True)
|
|
|
|
ch4 = cluster.add_instance('ch4', main_configs=["configs/config.d/clusters.xml", "configs/config.d/ddl.xml"],
|
|
|
|
with_zookeeper=True)
|
|
|
|
|
2019-12-12 10:27:02 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
2020-09-16 04:26:10 +00:00
|
|
|
ch1.query(
|
|
|
|
"CREATE TABLE sometbl ON CLUSTER 'cluster' (key UInt64, value String) ENGINE = MergeTree ORDER by key")
|
2019-12-12 10:27:02 +00:00
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_dictionary_ddl_on_cluster(started_cluster):
|
|
|
|
for node in [ch1, ch2, ch3, ch4]:
|
|
|
|
assert node.query("SELECT count() from sometbl") == "0\n"
|
|
|
|
|
|
|
|
for num, node in enumerate([ch1, ch2, ch3, ch4]):
|
|
|
|
node.query("insert into sometbl values ({}, '{}')".format(num, node.name))
|
|
|
|
|
|
|
|
ch1.query(
|
|
|
|
"""
|
|
|
|
CREATE DICTIONARY somedict ON CLUSTER 'cluster' (
|
|
|
|
key UInt64,
|
|
|
|
value String
|
|
|
|
)
|
|
|
|
PRIMARY KEY key
|
|
|
|
LAYOUT(FLAT())
|
|
|
|
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'sometbl' DB 'default'))
|
|
|
|
LIFETIME(10)
|
|
|
|
""")
|
|
|
|
|
|
|
|
for num, node in enumerate([ch1, ch2, ch3, ch4]):
|
|
|
|
assert node.query("SELECT count() from sometbl") == "1\n"
|
2020-09-16 04:26:10 +00:00
|
|
|
assert node.query(
|
|
|
|
"SELECT dictGetString('default.somedict', 'value', toUInt64({}))".format(num)) == node.name + '\n'
|
2019-12-12 10:27:02 +00:00
|
|
|
|
|
|
|
ch1.query("DETACH DICTIONARY default.somedict ON CLUSTER 'cluster'")
|
|
|
|
|
|
|
|
for node in [ch1, ch2, ch3, ch4]:
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node.query("SELECT dictGetString('default.somedict', 'value', toUInt64(1))")
|
|
|
|
|
|
|
|
ch1.query("ATTACH DICTIONARY default.somedict ON CLUSTER 'cluster'")
|
|
|
|
|
|
|
|
for num, node in enumerate([ch1, ch2, ch3, ch4]):
|
|
|
|
assert node.query("SELECT count() from sometbl") == "1\n"
|
2020-09-16 04:26:10 +00:00
|
|
|
assert node.query(
|
|
|
|
"SELECT dictGetString('default.somedict', 'value', toUInt64({}))".format(num)) == node.name + '\n'
|
2019-12-20 03:30:51 +00:00
|
|
|
|
|
|
|
for num, node in enumerate([ch1, ch2, ch3, ch4]):
|
|
|
|
node.query("ALTER TABLE sometbl UPDATE value = 'new_key' WHERE 1")
|
|
|
|
|
|
|
|
ch1.query("SYSTEM RELOAD DICTIONARY ON CLUSTER 'cluster' `default.somedict`")
|
|
|
|
|
|
|
|
for num, node in enumerate([ch1, ch2, ch3, ch4]):
|
2020-09-16 04:26:10 +00:00
|
|
|
assert node.query(
|
|
|
|
"SELECT dictGetString('default.somedict', 'value', toUInt64({}))".format(num)) == 'new_key' + '\n'
|
2019-12-20 03:30:51 +00:00
|
|
|
|
2019-12-12 10:27:02 +00:00
|
|
|
ch1.query("DROP DICTIONARY default.somedict ON CLUSTER 'cluster'")
|
|
|
|
|
|
|
|
for node in [ch1, ch2, ch3, ch4]:
|
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node.query("SELECT dictGetString('default.somedict', 'value', toUInt64(1))")
|