ClickHouse/tests/integration/test_user_defined_object_persistence/test.py

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

63 lines
2.0 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"
2024-08-02 09:13:41 +00:00
create_function_query3 = "CREATE FUNCTION MyUnion AS () -> (SELECT sum(s) FROM (SELECT 1 as s UNION ALL SELECT 1 as s))"
2021-07-20 20:42:23 +00:00
instance.query(create_function_query1)
instance.query(create_function_query2)
2024-08-02 09:13:41 +00:00
instance.query(create_function_query3)
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"
2024-08-02 09:13:41 +00:00
assert instance.query("SELECT MyUnion()") == "2\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"
2024-08-02 09:13:41 +00:00
assert instance.query("SELECT MyUnion()") == "2\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")
2024-08-02 09:13:41 +00:00
instance.query("DROP FUNCTION MyUnion")
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
error_message = instance.query_and_get_error("SELECT MySum1(1, 2)")
assert (
"Unknown function MySum1" in error_message
2024-05-17 08:23:32 +00:00
or "Function with name 'MySum1' does not exist. In scope SELECT MySum1(1, 2)"
in error_message
2021-07-21 09:41:17 +00:00
)
error_message = instance.query_and_get_error("SELECT MySum2(1, 2)")
assert (
"Unknown function MySum2" in error_message
2024-05-17 08:23:32 +00:00
or "Function with name 'MySum2' does not exist. In scope SELECT MySum2(1, 2)"
in error_message
2021-07-21 09:41:17 +00:00
)
2024-08-02 09:13:41 +00:00
error_message = instance.query_and_get_error("SELECT MyUnion()")
assert (
"Unknown function MyUnion" in error_message
or "Function with name 'MyUnion' does not exist. In scope SELECT MyUnion"
in error_message
)