diff --git a/src/TableFunctions/TableFunctionFactory.cpp b/src/TableFunctions/TableFunctionFactory.cpp index 79802d2ec77..3d2a72ddc9e 100644 --- a/src/TableFunctions/TableFunctionFactory.cpp +++ b/src/TableFunctions/TableFunctionFactory.cpp @@ -16,22 +16,15 @@ namespace ErrorCodes extern const int LOGICAL_ERROR; } -static const NameSet table_functions_allowed_in_readonly_mode -{ - "null", "view", "viewIfPermitted", "numbers", "numbers_mt", "generateRandom", "values", "cluster", "clusterAllReplicas" -}; - void TableFunctionFactory::registerFunction( - const std::string & name, TableFunctionCreator creator, Documentation doc, CaseSensitiveness case_sensitiveness) + const std::string & name, Value value, CaseSensitiveness case_sensitiveness) { - bool allowed_in_readonly_mode = table_functions_allowed_in_readonly_mode.contains(name); - - if (!table_functions.emplace(name, TableFunctionFactoryData{creator, {doc,allowed_in_readonly_mode}}).second) + if (!table_functions.emplace(name, value).second) throw Exception("TableFunctionFactory: the table function name '" + name + "' is not unique", ErrorCodes::LOGICAL_ERROR); if (case_sensitiveness == CaseInsensitive - && !case_insensitive_table_functions.emplace(Poco::toLower(name), TableFunctionFactoryData{creator, {doc,allowed_in_readonly_mode}}).second) + && !case_insensitive_table_functions.emplace(Poco::toLower(name), value).second) throw Exception("TableFunctionFactory: the case insensitive table function name '" + name + "' is not unique", ErrorCodes::LOGICAL_ERROR); } diff --git a/src/TableFunctions/TableFunctionFactory.h b/src/TableFunctions/TableFunctionFactory.h index 24b46d40de0..e2b8e29bd59 100644 --- a/src/TableFunctions/TableFunctionFactory.h +++ b/src/TableFunctions/TableFunctionFactory.h @@ -47,15 +47,16 @@ public: /// No locking, you must register all functions before usage of get. void registerFunction( const std::string & name, - TableFunctionCreator creator, - Documentation doc = {}, + Value value, CaseSensitiveness case_sensitiveness = CaseSensitive); template void registerFunction(Documentation doc = {}, CaseSensitiveness case_sensitiveness = CaseSensitive) { auto creator = []() -> TableFunctionPtr { return std::make_shared(); }; - registerFunction(Function::name, std::move(creator), std::move(doc), case_sensitiveness); + registerFunction(Function::name, + TableFunctionFactoryData{std::move(creator), {std::move(doc), table_functions_allowed_in_readonly_mode.contains(Function::name)}} , + case_sensitiveness); } /// Throws an exception if not found. @@ -81,6 +82,10 @@ private: TableFunctions table_functions; TableFunctions case_insensitive_table_functions; + + inline static const NameSet table_functions_allowed_in_readonly_mode = { + "null", "view", "viewIfPermitted", "numbers", "numbers_mt", "generateRandom", "values", "cluster", "clusterAllReplicas" + }; }; }