mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
118 lines
2.9 KiB
Python
118 lines
2.9 KiB
Python
|
import pytest
|
||
|
from helpers.cluster import ClickHouseCluster
|
||
|
|
||
|
cluster = ClickHouseCluster(__file__)
|
||
|
ch1 = cluster.add_instance(
|
||
|
"ch1",
|
||
|
main_configs=[
|
||
|
"configs/config.d/clusters.xml",
|
||
|
"configs/config.d/distributed_ddl.xml",
|
||
|
],
|
||
|
with_zookeeper=True,
|
||
|
macros={"replica": "node1"},
|
||
|
stay_alive=True,
|
||
|
)
|
||
|
|
||
|
database_name = "modify_engine_args"
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope="module")
|
||
|
def started_cluster():
|
||
|
try:
|
||
|
cluster.start()
|
||
|
yield cluster
|
||
|
|
||
|
finally:
|
||
|
cluster.shutdown()
|
||
|
|
||
|
|
||
|
def q(node, query):
|
||
|
return node.query(database=database_name, sql=query)
|
||
|
|
||
|
|
||
|
def create_tables():
|
||
|
# Check one argument
|
||
|
q(
|
||
|
ch1,
|
||
|
"CREATE TABLE replacing_ver ( A Int64, D Date, S String ) ENGINE = ReplacingMergeTree(D) PARTITION BY toYYYYMM(D) ORDER BY A",
|
||
|
)
|
||
|
|
||
|
# Check more than one argument
|
||
|
q(
|
||
|
ch1,
|
||
|
"CREATE TABLE collapsing_ver ( ID UInt64, Sign Int8, Version UInt8 ) ENGINE = VersionedCollapsingMergeTree(Sign, Version) ORDER BY ID",
|
||
|
)
|
||
|
|
||
|
|
||
|
def check_tables():
|
||
|
# Check tables exists
|
||
|
assert (
|
||
|
q(
|
||
|
ch1,
|
||
|
"SHOW TABLES",
|
||
|
).strip()
|
||
|
== "collapsing_ver\nreplacing_ver"
|
||
|
)
|
||
|
|
||
|
replacing_uuid = q(
|
||
|
ch1,
|
||
|
f"SELECT uuid FROM system.tables WHERE database = '{database_name}' and name = 'replacing_ver'",
|
||
|
).strip()
|
||
|
collapsing_uuid = q(
|
||
|
ch1,
|
||
|
f"SELECT uuid FROM system.tables WHERE database = '{database_name}' and name = 'collapsing_ver'",
|
||
|
).strip()
|
||
|
|
||
|
# Check engines
|
||
|
assert (
|
||
|
q(
|
||
|
ch1,
|
||
|
f"SELECT engine_full FROM system.tables WHERE database = '{database_name}' and name = 'replacing_ver'",
|
||
|
)
|
||
|
.strip()
|
||
|
.startswith(
|
||
|
f"ReplicatedReplacingMergeTree(\\'/clickhouse/tables/{replacing_uuid}/{{shard}}\\', \\'{{replica}}\\', D)"
|
||
|
)
|
||
|
)
|
||
|
assert (
|
||
|
q(
|
||
|
ch1,
|
||
|
f"SELECT engine_full FROM system.tables WHERE database = '{database_name}' and name = 'collapsing_ver'",
|
||
|
)
|
||
|
.strip()
|
||
|
.startswith(
|
||
|
f"ReplicatedVersionedCollapsingMergeTree(\\'/clickhouse/tables/{collapsing_uuid}/{{shard}}\\', \\'{{replica}}\\', Sign, Version)"
|
||
|
)
|
||
|
)
|
||
|
|
||
|
|
||
|
def set_convert_flags():
|
||
|
# Set convert flag on actually convertable tables
|
||
|
for table in ["replacing_ver", "collapsing_ver"]:
|
||
|
ch1.exec_in_container(
|
||
|
[
|
||
|
"bash",
|
||
|
"-c",
|
||
|
f"mkdir /var/lib/clickhouse/data/{database_name}/{table}/flags",
|
||
|
]
|
||
|
)
|
||
|
ch1.exec_in_container(
|
||
|
[
|
||
|
"bash",
|
||
|
"-c",
|
||
|
f"touch /var/lib/clickhouse/data/{database_name}/{table}/flags/convert_to_replicated",
|
||
|
]
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_modify_engine_on_restart(started_cluster):
|
||
|
ch1.query("CREATE DATABASE " + database_name)
|
||
|
|
||
|
create_tables()
|
||
|
|
||
|
set_convert_flags()
|
||
|
|
||
|
ch1.restart_clickhouse()
|
||
|
|
||
|
check_tables()
|