2022-11-11 21:19:58 +00:00
|
|
|
#include <Interpreters/InterpreterCreateNamedCollectionQuery.h>
|
2024-01-09 06:33:48 +00:00
|
|
|
#include <Interpreters/InterpreterFactory.h>
|
2022-11-11 21:19:58 +00:00
|
|
|
#include <Parsers/ASTCreateNamedCollectionQuery.h>
|
|
|
|
#include <Access/ContextAccess.h>
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Interpreters/executeDDLQueryOnCluster.h>
|
2022-12-16 22:57:09 +00:00
|
|
|
#include <Common/NamedCollections/NamedCollectionUtils.h>
|
2022-11-11 21:19:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
BlockIO InterpreterCreateNamedCollectionQuery::execute()
|
|
|
|
{
|
|
|
|
auto current_context = getContext();
|
|
|
|
const auto & query = query_ptr->as<const ASTCreateNamedCollectionQuery &>();
|
|
|
|
|
2023-02-11 18:57:41 +00:00
|
|
|
current_context->checkAccess(AccessType::CREATE_NAMED_COLLECTION, query.collection_name);
|
|
|
|
|
2022-11-11 21:19:58 +00:00
|
|
|
if (!query.cluster.empty())
|
|
|
|
{
|
|
|
|
DDLQueryOnClusterParams params;
|
|
|
|
return executeDDLQueryOnCluster(query_ptr, current_context, params);
|
|
|
|
}
|
|
|
|
|
2022-11-15 14:49:25 +00:00
|
|
|
NamedCollectionUtils::createFromSQL(query, current_context);
|
2022-11-11 21:19:58 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-01-09 06:33:48 +00:00
|
|
|
void registerInterpreterCreateNamedCollectionQuery(InterpreterFactory & factory)
|
|
|
|
{
|
|
|
|
auto create_fn = [] (const InterpreterFactory::Arguments & args)
|
|
|
|
{
|
|
|
|
return std::make_unique<InterpreterCreateNamedCollectionQuery>(args.query, args.context);
|
|
|
|
};
|
|
|
|
factory.registerInterpreter("InterpreterCreateNamedCollectionQuery", create_fn);
|
|
|
|
}
|
|
|
|
|
2022-11-11 21:19:58 +00:00
|
|
|
}
|