2021-10-20 09:43:03 +00:00
|
|
|
#include <Interpreters/InterpreterCreateFunctionQuery.h>
|
|
|
|
|
2021-07-19 23:34:04 +00:00
|
|
|
#include <Access/ContextAccess.h>
|
2022-09-24 21:24:39 +00:00
|
|
|
#include <Functions/UserDefined/IUserDefinedSQLObjectsLoader.h>
|
|
|
|
#include <Functions/UserDefined/UserDefinedSQLFunctionFactory.h>
|
2021-07-19 23:34:04 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2021-10-27 08:28:21 +00:00
|
|
|
#include <Interpreters/executeDDLQueryOnCluster.h>
|
2021-11-26 17:21:54 +00:00
|
|
|
#include <Parsers/ASTCreateFunctionQuery.h>
|
2021-10-20 09:43:03 +00:00
|
|
|
|
2021-08-23 14:31:58 +00:00
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-05-10 22:35:22 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2022-09-24 21:24:39 +00:00
|
|
|
extern const int INCORRECT_QUERY;
|
2021-05-10 22:35:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
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
|
|
|
|
2021-10-27 08:28:21 +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);
|
|
|
|
|
2022-09-24 21:24:39 +00:00
|
|
|
auto current_context = getContext();
|
|
|
|
|
2021-10-27 15:49:18 +00:00
|
|
|
if (!create_function_query.cluster.empty())
|
2022-04-22 12:15:29 +00:00
|
|
|
{
|
2022-09-24 21:24:39 +00:00
|
|
|
if (current_context->getUserDefinedSQLObjectsLoader().isReplicated())
|
|
|
|
throw Exception(ErrorCodes::INCORRECT_QUERY, "ON CLUSTER is not allowed because used-defined functions are replicated automatically");
|
|
|
|
|
2022-04-22 12:15:29 +00:00
|
|
|
DDLQueryOnClusterParams params;
|
|
|
|
params.access_to_check = std::move(access_rights_elements);
|
2022-09-24 21:24:39 +00:00
|
|
|
return executeDDLQueryOnCluster(query_ptr, current_context, params);
|
2022-04-22 12:15:29 +00:00
|
|
|
}
|
2021-10-27 08:28:21 +00:00
|
|
|
|
|
|
|
current_context->checkAccess(access_rights_elements);
|
|
|
|
|
2022-01-20 08:23:52 +00:00
|
|
|
auto function_name = create_function_query.getFunctionName();
|
2022-09-24 21:24:39 +00:00
|
|
|
bool throw_if_exists = !create_function_query.if_not_exists && !create_function_query.or_replace;
|
|
|
|
bool replace_if_exists = create_function_query.or_replace;
|
2021-10-20 13:04:02 +00:00
|
|
|
|
2022-09-24 21:24:39 +00:00
|
|
|
UserDefinedSQLFunctionFactory::instance().registerFunction(current_context, function_name, query_ptr, throw_if_exists, replace_if_exists);
|
2021-08-18 09:29:52 +00:00
|
|
|
|
2021-05-09 09:47:29 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|