ClickHouse/src/Interpreters/InterpreterUseQuery.cpp
Bharat Nallan ee37f551a2
independent registration of interpreters (#58443)
* make interpreter factory an instance

* add registerInterpreter

* register interpreters individually

* try wire everything up

* fix style

* fix test
2024-01-08 22:33:48 -08:00

30 lines
831 B
C++

#include <Parsers/ASTUseQuery.h>
#include <Interpreters/Context.h>
#include <Interpreters/InterpreterFactory.h>
#include <Interpreters/InterpreterUseQuery.h>
#include <Access/Common/AccessFlags.h>
#include <Common/typeid_cast.h>
namespace DB
{
BlockIO InterpreterUseQuery::execute()
{
const String & new_database = query_ptr->as<ASTUseQuery &>().getDatabase();
getContext()->checkAccess(AccessType::SHOW_DATABASES, new_database);
getContext()->getSessionContext()->setCurrentDatabase(new_database);
return {};
}
void registerInterpreterUseQuery(InterpreterFactory & factory)
{
auto create_fn = [] (const InterpreterFactory::Arguments & args)
{
return std::make_unique<InterpreterUseQuery>(args.query, args.context);
};
factory.registerInterpreter("InterpreterUseQuery", create_fn);
}
}