Tests for replicated system.functions

This commit is contained in:
Aleksei Filatov 2023-02-06 18:53:20 +03:00
parent 690d8355ca
commit cf6ca10c83
5 changed files with 49 additions and 3 deletions

View File

@ -1,5 +1,4 @@
#include "UserDefinedSQLObjectType.h"
#include <base/defines.h>
namespace DB
{
@ -11,7 +10,6 @@ const char * toString(UserDefinedSQLObjectType type)
case UserDefinedSQLObjectType::Function:
return "FUNCTION";
}
UNREACHABLE();
}
}

View File

@ -31,6 +31,7 @@ void backupUserDefinedSQLObjects(
const std::vector<std::pair<String, ASTPtr>> & objects)
{
std::vector<std::pair<String, BackupEntryPtr>> backup_entries;
backup_entries.reserve(objects.size());
for (const auto & [object_name, create_object_query] : objects)
backup_entries.emplace_back(
escapeForFileName(object_name) + ".sql", std::make_shared<BackupEntryFromMemory>(queryToString(create_object_query)));

View File

@ -144,7 +144,6 @@ void UserDefinedSQLObjectsLoaderFromZooKeeper::processWatchQueue()
continue;
auto zookeeper = getZooKeeper();
const auto & [object_type, object_name] = watched_object;
if (object_name.empty())

View File

@ -0,0 +1,3 @@
<clickhouse>
<user_defined_zookeeper_path>/clickhouse/udf</user_defined_zookeeper_path>
</clickhouse>

View File

@ -11,6 +11,7 @@ cluster = ClickHouseCluster(__file__)
main_configs = [
"configs/remote_servers.xml",
"configs/replicated_access_storage.xml",
"configs/replicated_user_defined_sql_objects.xml",
"configs/backups_disk.xml",
"configs/lesser_timeouts.xml", # Default timeouts are quite big (a few minutes), the tests don't need them to be that big.
]
@ -604,6 +605,50 @@ def test_system_users():
assert node1.query("SHOW GRANTS FOR u1") == "GRANT SELECT ON default.tbl TO u1\n"
def test_system_functions():
node1.query("CREATE FUNCTION linear_equation AS (x, k, b) -> k*x + b;")
node1.query("CREATE FUNCTION parity_str AS (n) -> if(n % 2, 'odd', 'even');")
backup_name = new_backup_name()
node1.query(f"BACKUP TABLE system.functions ON CLUSTER 'cluster' TO {backup_name}")
node1.query("DROP FUNCTION linear_equation")
node1.query("DROP FUNCTION parity_str")
assert_eq_with_retry(
node2, "SELECT name FROM system.functions WHERE name='parity_str'", ""
)
node1.query(
f"RESTORE TABLE system.functions ON CLUSTER 'cluster' FROM {backup_name}"
)
assert node1.query(
"SELECT number, linear_equation(number, 2, 1) FROM numbers(3)"
) == TSV([[0, 1], [1, 3], [2, 5]])
assert node1.query("SELECT number, parity_str(number) FROM numbers(3)") == TSV(
[[0, "even"], [1, "odd"], [2, "even"]]
)
assert node2.query(
"SELECT number, linear_equation(number, 2, 1) FROM numbers(3)"
) == TSV([[0, 1], [1, 3], [2, 5]])
assert node2.query("SELECT number, parity_str(number) FROM numbers(3)") == TSV(
[[0, "even"], [1, "odd"], [2, "even"]]
)
assert_eq_with_retry(
node2,
"SELECT name FROM system.functions WHERE name='parity_str'",
"parity_str\n",
)
assert node2.query("SELECT number, parity_str(number) FROM numbers(3)") == TSV(
[[0, "even"], [1, "odd"], [2, "even"]]
)
def test_projection():
node1.query(
"CREATE TABLE tbl ON CLUSTER 'cluster' (x UInt32, y String) ENGINE=ReplicatedMergeTree('/clickhouse/tables/tbl/', '{replica}') "