mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 18:32:29 +00:00
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include <Parsers/ASTDropFunctionQuery.h>
|
|
|
|
#include <Access/ContextAccess.h>
|
|
#include <Functions/UserDefined/IUserDefinedSQLObjectsLoader.h>
|
|
#include <Functions/UserDefined/UserDefinedSQLFunctionFactory.h>
|
|
#include <Interpreters/Context.h>
|
|
#include <Interpreters/FunctionNameNormalizer.h>
|
|
#include <Interpreters/InterpreterDropFunctionQuery.h>
|
|
#include <Interpreters/executeDDLQueryOnCluster.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int INCORRECT_QUERY;
|
|
}
|
|
|
|
BlockIO InterpreterDropFunctionQuery::execute()
|
|
{
|
|
FunctionNameNormalizer().visit(query_ptr.get());
|
|
ASTDropFunctionQuery & drop_function_query = query_ptr->as<ASTDropFunctionQuery &>();
|
|
|
|
AccessRightsElements access_rights_elements;
|
|
access_rights_elements.emplace_back(AccessType::DROP_FUNCTION);
|
|
|
|
auto current_context = getContext();
|
|
|
|
if (!drop_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);
|
|
|
|
bool throw_if_not_exists = !drop_function_query.if_exists;
|
|
|
|
UserDefinedSQLFunctionFactory::instance().unregisterFunction(current_context, drop_function_query.function_name, throw_if_not_exists);
|
|
|
|
return {};
|
|
}
|
|
|
|
}
|