ClickHouse/tests/integration/test_user_defined_object_persistence/test.py

40 lines
1.1 KiB
Python
Raw Normal View History

2021-07-20 20:42:23 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
2021-07-21 13:04:52 +00:00
instance = cluster.add_instance('instance', stay_alive=True)
2021-07-20 20:42:23 +00:00
@pytest.fixture(scope="module", autouse=True)
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_persistence():
create_function_query1 = "CREATE FUNCTION MySum1 AS (a, b) -> a + b"
create_function_query2 = "CREATE FUNCTION MySum2 AS (a, b) -> MySum1(a, b) + b"
instance.query(create_function_query1)
instance.query(create_function_query2)
2021-07-21 07:29:26 +00:00
assert instance.query("SELECT MySum1(1,2)") == "3\n"
assert instance.query("SELECT MySum2(1,2)") == "5\n"
2021-07-20 20:42:23 +00:00
2021-07-21 11:10:37 +00:00
instance.restart_clickhouse()
2021-07-20 20:42:23 +00:00
2021-07-21 09:41:17 +00:00
assert instance.query("SELECT MySum1(1,2)") == "3\n"
assert instance.query("SELECT MySum2(1,2)") == "5\n"
2021-07-20 20:42:23 +00:00
2021-07-21 09:41:17 +00:00
instance.query("DROP FUNCTION MySum2")
instance.query("DROP FUNCTION MySum1")
2021-07-20 20:42:23 +00:00
2021-07-21 11:10:37 +00:00
instance.restart_clickhouse()
2021-07-20 20:42:23 +00:00
2021-07-21 09:41:17 +00:00
assert "Unknown function MySum1" in instance.query_and_get_error("SELECT MySum1(1, 2)")
assert "Unknown function MySum2" in instance.query_and_get_error("SELECT MySum2(1, 2)")