mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Updated registerFunction method to take TableFunctionFactoryData as input , moved table_functions_allowed_in_readonly_mode inside TableFunctionFactory- 42414 Enable table functions in readonly mode
This commit is contained in:
parent
54035270b2
commit
b689f7ab70
@ -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);
|
||||
}
|
||||
|
@ -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 <typename Function>
|
||||
void registerFunction(Documentation doc = {}, CaseSensitiveness case_sensitiveness = CaseSensitive)
|
||||
{
|
||||
auto creator = []() -> TableFunctionPtr { return std::make_shared<Function>(); };
|
||||
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"
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user