2024-01-09 06:33:48 +00:00
|
|
|
#include <Interpreters/InterpreterFactory.h>
|
2023-08-03 09:44:44 +00:00
|
|
|
#include <Interpreters/InterpreterDropFunctionQuery.h>
|
2021-10-27 08:28:21 +00:00
|
|
|
|
2021-07-19 23:34:04 +00:00
|
|
|
#include <Access/ContextAccess.h>
|
2023-12-12 14:03:49 +00:00
|
|
|
#include <Functions/UserDefined/IUserDefinedSQLObjectsStorage.h>
|
2022-09-24 21:24:39 +00:00
|
|
|
#include <Functions/UserDefined/UserDefinedSQLFunctionFactory.h>
|
2021-07-19 23:34:04 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2021-05-14 22:43:04 +00:00
|
|
|
#include <Interpreters/FunctionNameNormalizer.h>
|
2021-10-27 08:28:21 +00:00
|
|
|
#include <Interpreters/executeDDLQueryOnCluster.h>
|
2023-08-03 09:44:44 +00:00
|
|
|
#include <Interpreters/removeOnClusterClauseIfNeeded.h>
|
|
|
|
#include <Parsers/ASTDropFunctionQuery.h>
|
2021-05-14 22:43:04 +00:00
|
|
|
|
2021-07-19 23:34:04 +00:00
|
|
|
|
2021-05-14 22:43:04 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-09-24 21:24:39 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int INCORRECT_QUERY;
|
|
|
|
}
|
|
|
|
|
2021-10-27 08:28:21 +00:00
|
|
|
BlockIO InterpreterDropFunctionQuery::execute()
|
|
|
|
{
|
2021-05-14 22:43:04 +00:00
|
|
|
FunctionNameNormalizer().visit(query_ptr.get());
|
2023-08-03 09:44:44 +00:00
|
|
|
|
|
|
|
const auto updated_query_ptr = removeOnClusterClauseIfNeeded(query_ptr, getContext());
|
|
|
|
ASTDropFunctionQuery & drop_function_query = updated_query_ptr->as<ASTDropFunctionQuery &>();
|
2021-10-27 08:28:21 +00:00
|
|
|
|
|
|
|
AccessRightsElements access_rights_elements;
|
|
|
|
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 (!drop_function_query.cluster.empty())
|
2022-04-22 12:15:29 +00:00
|
|
|
{
|
2023-12-12 14:03:49 +00:00
|
|
|
if (current_context->getUserDefinedSQLObjectsStorage().isReplicated())
|
2022-09-24 21:24:39 +00:00
|
|
|
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);
|
2023-08-03 09:44:44 +00:00
|
|
|
return executeDDLQueryOnCluster(updated_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);
|
2021-08-23 14:31:58 +00:00
|
|
|
|
2022-09-24 21:24:39 +00:00
|
|
|
bool throw_if_not_exists = !drop_function_query.if_exists;
|
|
|
|
|
|
|
|
UserDefinedSQLFunctionFactory::instance().unregisterFunction(current_context, drop_function_query.function_name, throw_if_not_exists);
|
2021-08-18 09:29:52 +00:00
|
|
|
|
2021-05-14 22:43:04 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-01-09 06:33:48 +00:00
|
|
|
void registerInterpreterDropFunctionQuery(InterpreterFactory & factory)
|
|
|
|
{
|
|
|
|
auto create_fn = [] (const InterpreterFactory::Arguments & args)
|
|
|
|
{
|
|
|
|
return std::make_unique<InterpreterDropFunctionQuery>(args.query, args.context);
|
|
|
|
};
|
|
|
|
factory.registerInterpreter("InterpreterDropFunctionQuery", create_fn);
|
|
|
|
}
|
|
|
|
|
2021-05-14 22:43:04 +00:00
|
|
|
}
|