ClickHouse/tests/integration/test_analyzer_compatibility/test.py

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

128 lines
3.4 KiB
Python
Raw Normal View History

2024-08-01 16:51:44 +00:00
import time
2024-09-27 10:19:39 +00:00
import uuid
2024-07-02 22:51:21 +00:00
import pytest
2024-09-27 10:19:39 +00:00
2024-07-02 22:51:21 +00:00
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import TSV
CLICKHOUSE_MAX_VERSION_WITH_ANALYZER_DISABLED_BY_DEFAULT = "24.2"
cluster = ClickHouseCluster(__file__)
# Here analyzer is enabled by default
current = cluster.add_instance(
"current",
main_configs=["configs/remote_servers.xml"],
)
# Here analyzer is disabled by default
backward = cluster.add_instance(
"backward",
use_old_analyzer=True,
main_configs=["configs/remote_servers.xml"],
image="clickhouse/clickhouse-server",
tag=CLICKHOUSE_MAX_VERSION_WITH_ANALYZER_DISABLED_BY_DEFAULT,
with_installed_binary=True,
)
2024-07-02 22:59:22 +00:00
2024-07-02 22:51:21 +00:00
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_two_new_versions(start_cluster):
# Two new versions (both know about the analyzer)
# One have it enabled by default, another one - disabled.
current.query("SYSTEM FLUSH LOGS")
backward.query("SYSTEM FLUSH LOGS")
query_id = str(uuid.uuid4())
2024-07-02 22:59:22 +00:00
current.query(
"SELECT * FROM clusterAllReplicas('test_cluster_mixed', system.tables);",
query_id=query_id,
)
2024-07-02 22:51:21 +00:00
current.query("SYSTEM FLUSH LOGS")
backward.query("SYSTEM FLUSH LOGS")
2024-07-02 22:59:22 +00:00
assert (
current.query(
"""
2024-08-01 16:51:44 +00:00
SELECT hostname() AS h, getSetting('allow_experimental_analyzer')
2024-07-02 22:51:21 +00:00
FROM clusterAllReplicas('test_cluster_mixed', system.one)
2024-07-02 22:59:22 +00:00
ORDER BY h;"""
)
== TSV([["backward", "true"], ["current", "true"]])
)
2024-07-02 22:51:21 +00:00
2024-08-01 16:51:44 +00:00
# Should be enabled explicitly on the old instance.
analyzer_enabled = backward.query(
2024-07-02 22:59:22 +00:00
f"""
2024-07-02 22:51:21 +00:00
SELECT
2024-08-01 16:51:44 +00:00
DISTINCT Settings['allow_experimental_analyzer']
FROM system.query_log
2024-07-02 22:59:22 +00:00
WHERE initial_query_id = '{query_id}';"""
)
2024-07-02 22:51:21 +00:00
assert TSV(analyzer_enabled) == TSV("1")
query_id = str(uuid.uuid4())
2024-07-02 22:59:22 +00:00
backward.query(
"SELECT * FROM clusterAllReplicas('test_cluster_mixed', system.tables)",
query_id=query_id,
)
2024-07-02 22:51:21 +00:00
current.query("SYSTEM FLUSH LOGS")
backward.query("SYSTEM FLUSH LOGS")
2024-08-01 15:53:08 +00:00
# The old version doesn't know about the alias.
# For this we will ask about the old experimental name.
2024-07-02 22:59:22 +00:00
assert (
backward.query(
"""
2024-08-01 15:53:08 +00:00
SELECT hostname() AS h, getSetting('allow_experimental_analyzer')
2024-07-02 22:51:21 +00:00
FROM clusterAllReplicas('test_cluster_mixed', system.one)
2024-07-02 22:59:22 +00:00
ORDER BY h;"""
)
== TSV([["backward", "false"], ["current", "false"]])
)
2024-07-02 22:51:21 +00:00
# Should be disabled everywhere
2024-07-02 22:59:22 +00:00
analyzer_enabled = backward.query(
f"""
2024-07-02 22:51:21 +00:00
SELECT
2024-08-01 15:53:08 +00:00
DISTINCT Settings['allow_experimental_analyzer']
2024-07-02 22:51:21 +00:00
FROM clusterAllReplicas('test_cluster_mixed', system.query_log)
2024-07-02 22:59:22 +00:00
WHERE initial_query_id = '{query_id}';"""
)
2024-07-02 22:51:21 +00:00
assert TSV(analyzer_enabled) == TSV("0")
2024-08-01 16:51:44 +00:00
# Only new version knows about the alias
# and it will send the old setting `allow_experimental_analyzer`
# to the remote server.
query_id = str(uuid.uuid4())
current.query(
"SELECT * FROM clusterAllReplicas('test_cluster_mixed', system.tables) SETTINGS enable_analyzer = 1;",
query_id=query_id,
)
current.query("SYSTEM FLUSH LOGS")
backward.query("SYSTEM FLUSH LOGS")
# Should be disabled explicitly everywhere.
analyzer_enabled = current.query(
f"""
SELECT
DISTINCT Settings['allow_experimental_analyzer']
FROM system.query_log
WHERE initial_query_id = '{query_id}';"""
)
assert TSV(analyzer_enabled) == TSV("1")