ClickHouse/src/Interpreters/InterpreterCreateFunctionQuery.cpp

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

53 lines
1.7 KiB
C++
Raw Normal View History

#include <Interpreters/InterpreterCreateFunctionQuery.h>
2021-07-19 23:34:04 +00:00
#include <Access/ContextAccess.h>
#include <Functions/UserDefined/IUserDefinedSQLObjectsLoader.h>
#include <Functions/UserDefined/UserDefinedSQLFunctionFactory.h>
2021-07-19 23:34:04 +00:00
#include <Interpreters/Context.h>
#include <Interpreters/executeDDLQueryOnCluster.h>
#include <Parsers/ASTCreateFunctionQuery.h>
2021-08-23 14:31:58 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int INCORRECT_QUERY;
}
BlockIO InterpreterCreateFunctionQuery::execute()
{
2021-10-27 15:49:18 +00:00
ASTCreateFunctionQuery & create_function_query = query_ptr->as<ASTCreateFunctionQuery &>();
2021-08-18 09:29:52 +00:00
AccessRightsElements access_rights_elements;
access_rights_elements.emplace_back(AccessType::CREATE_FUNCTION);
2021-10-27 15:49:18 +00:00
if (create_function_query.or_replace)
access_rights_elements.emplace_back(AccessType::DROP_FUNCTION);
auto current_context = getContext();
2021-10-27 15:49:18 +00:00
if (!create_function_query.cluster.empty())
{
if (current_context->getUserDefinedSQLObjectsLoader().isReplicated())
throw Exception(ErrorCodes::INCORRECT_QUERY, "ON CLUSTER is not allowed because used-defined functions are replicated automatically");
DDLQueryOnClusterParams params;
params.access_to_check = std::move(access_rights_elements);
return executeDDLQueryOnCluster(query_ptr, current_context, params);
}
current_context->checkAccess(access_rights_elements);
2022-01-20 08:23:52 +00:00
auto function_name = create_function_query.getFunctionName();
bool throw_if_exists = !create_function_query.if_not_exists && !create_function_query.or_replace;
bool replace_if_exists = create_function_query.or_replace;
UserDefinedSQLFunctionFactory::instance().registerFunction(current_context, function_name, query_ptr, throw_if_exists, replace_if_exists);
2021-08-18 09:29:52 +00:00
return {};
}
}