/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see .
*/
#include
#include "cql3/statements/drop_function_statement.hh"
#include "cql3/functions/functions.hh"
#include "cql3/functions/user_function.hh"
#include "prepared_statement.hh"
#include "service/migration_manager.hh"
#include "cql3/query_processor.hh"
#include "mutation.hh"
namespace cql3 {
namespace statements {
std::unique_ptr drop_function_statement::prepare(data_dictionary::database db, cql_stats& stats) {
return std::make_unique(make_shared(*this));
}
future, std::vector>>
drop_function_statement::prepare_schema_mutations(query_processor& qp) const {
::shared_ptr ret;
std::vector m;
auto func = validate_while_executing(qp);
if (func) {
auto user_func = dynamic_pointer_cast(func);
if (!user_func) {
throw exceptions::invalid_request_exception(format("'{}' is not a user defined function", func));
}
if (auto aggregate = functions::functions::used_by_user_aggregate(user_func->name()); bool(aggregate)) {
throw exceptions::invalid_request_exception(format("Cannot delete function {}, as it is used by user-defined aggregate {}", func, *aggregate));
}
m = co_await qp.get_migration_manager().prepare_function_drop_announcement(user_func);
ret = create_schema_change(*func, false);
}
co_return std::make_pair(std::move(ret), std::move(m));
}
drop_function_statement::drop_function_statement(functions::function_name name,
std::vector> arg_types, bool args_present, bool if_exists)
: drop_function_statement_base(std::move(name), std::move(arg_types), args_present, if_exists) {}
}
}