ClickHouse/tests/integration/test_dictionary_custom_settings/test.py

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

91 lines
2.6 KiB
Python
Raw Normal View History

import os
import pytest
2024-09-27 10:19:39 +00:00
from helpers.cluster import ClickHouseCluster
2023-08-03 12:33:29 +00:00
from helpers.test_tools import assert_eq_with_retry
DICTIONARY_FILES = [
"configs/dictionaries/FileSourceConfig.xml",
"configs/dictionaries/ExecutableSourceConfig.xml",
"configs/dictionaries/source.csv",
"configs/dictionaries/HTTPSourceConfig.xml",
"configs/dictionaries/ClickHouseSourceConfig.xml",
]
cluster = ClickHouseCluster(__file__)
2021-05-31 04:17:08 +00:00
instance = cluster.add_instance("node", dictionaries=DICTIONARY_FILES)
def prepare():
node = instance
path = "/source.csv"
script_dir = os.path.dirname(os.path.realpath(__file__))
node.copy_file_to_container(
os.path.join(script_dir, "./http_server.py"), "/http_server.py"
)
node.copy_file_to_container(
os.path.join(script_dir, "configs/dictionaries/source.csv"), "./source.csv"
)
node.exec_in_container(
[
"bash",
"-c",
2020-10-02 16:54:07 +00:00
"python3 /http_server.py --data-path={tbl} --schema=http --host=localhost --port=5555".format(
tbl=path
),
],
detach=True,
)
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
prepare()
yield cluster
finally:
cluster.shutdown()
2020-09-15 15:42:46 +00:00
def test_work(start_cluster):
query = instance.query
2020-09-15 15:42:46 +00:00
instance.query("SYSTEM RELOAD DICTIONARIES")
assert query("SELECT dictGetString('test_file', 'first', toUInt64(1))") == "\\'a\n"
assert query("SELECT dictGetString('test_file', 'second', toUInt64(1))") == '"b\n'
assert (
query("SELECT dictGetString('test_executable', 'first', toUInt64(1))")
== "\\'a\n"
)
assert (
query("SELECT dictGetString('test_executable', 'second', toUInt64(1))")
== '"b\n'
)
caught_exception = ""
try:
2020-04-10 16:09:44 +00:00
instance.query(
"CREATE TABLE source (id UInt64, first String, second String, third String) ENGINE=TinyLog;"
)
instance.query(
"INSERT INTO default.source VALUES (1, 'aaa', 'bbb', 'cccc'), (2, 'ddd', 'eee', 'fff')"
)
instance.query("SELECT dictGetString('test_clickhouse', 'second', toUInt64(1))")
except Exception as e:
caught_exception = str(e)
assert caught_exception.find("Limit for result exceeded") != -1
2023-08-03 12:33:29 +00:00
# It is possible that the HTTP server takes long time to start accepting connections
2023-08-03 12:55:27 +00:00
assert_eq_with_retry(
instance, "SELECT dictGetString('test_http', 'first', toUInt64(1))", "\\'a\n"
)
assert_eq_with_retry(
instance, "SELECT dictGetString('test_http', 'second', toUInt64(1))", '"b\n'
)