ClickHouse/tests/integration/test_attach_table_normalizer/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.4 KiB
Python
Raw Normal View History

2022-06-17 08:42:05 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
2023-06-28 03:40:09 +00:00
node = cluster.add_instance("node", stay_alive=True)
2022-06-17 08:42:05 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2023-02-26 01:33:56 +00:00
2022-06-17 08:42:05 +00:00
def replace_substring_to_substr(node):
2023-06-27 06:01:15 +00:00
node.exec_in_container(
2023-02-26 01:33:56 +00:00
[
"bash",
"-c",
"sed -i 's/substring/substr/g' /var/lib/clickhouse/metadata/default/file.sql",
],
2023-06-27 06:01:15 +00:00
user="root",
2023-02-26 01:33:56 +00:00
)
2022-06-17 08:42:05 +00:00
2023-02-25 22:28:13 +00:00
def test_attach_substr(started_cluster):
2022-06-17 08:42:05 +00:00
# Initialize
2022-06-18 09:13:50 +00:00
node.query("DROP TABLE IF EXISTS default.file")
2023-02-26 01:33:56 +00:00
node.query(
"CREATE TABLE default.file(`s` String, `n` UInt8) ENGINE = MergeTree PARTITION BY substring(s, 1, 2) ORDER BY n "
)
2022-06-17 08:42:05 +00:00
# Detach table file
node.query("DETACH TABLE file")
2022-06-18 09:13:50 +00:00
# Replace substring to substr
2022-06-17 08:42:05 +00:00
replace_substring_to_substr(node)
# Attach table file
node.query("ATTACH TABLE file")
2023-02-26 01:33:56 +00:00
2023-02-25 22:28:13 +00:00
def test_attach_substr_restart(started_cluster):
2022-06-17 08:42:05 +00:00
# Initialize
2022-06-18 09:13:50 +00:00
node.query("DROP TABLE IF EXISTS default.file")
2023-02-26 01:33:56 +00:00
node.query(
"CREATE TABLE default.file(`s` String, `n` UInt8) ENGINE = MergeTree PARTITION BY substring(s, 1, 2) ORDER BY n "
)
2022-06-17 08:42:05 +00:00
2022-06-18 09:13:50 +00:00
# Replace substring to substr
2022-06-17 08:42:05 +00:00
replace_substring_to_substr(node)
# Restart clickhouse
node.restart_clickhouse(kill=True)