2020-07-06 13:57:45 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Interpreters/InterpreterExternalDDLQuery.h>
|
2020-08-07 04:55:45 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2020-07-06 13:57:45 +00:00
|
|
|
|
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Parsers/ASTDropQuery.h>
|
|
|
|
#include <Parsers/ASTRenameQuery.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/ASTExternalDDLQuery.h>
|
|
|
|
|
|
|
|
#ifdef USE_MYSQL
|
2020-07-21 09:56:55 +00:00
|
|
|
# include <Interpreters/MySQL/InterpretersMySQLDDLQuery.h>
|
2020-07-13 04:16:28 +00:00
|
|
|
# include <Parsers/MySQL/ASTAlterQuery.h>
|
2020-07-06 13:57:45 +00:00
|
|
|
# include <Parsers/MySQL/ASTCreateQuery.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-07-21 09:56:55 +00:00
|
|
|
extern const int SYNTAX_ERROR;
|
2020-07-06 13:57:45 +00:00
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
2021-05-31 14:49:02 +00:00
|
|
|
InterpreterExternalDDLQuery::InterpreterExternalDDLQuery(const ASTPtr & query_, ContextMutablePtr context_)
|
|
|
|
: WithMutableContext(context_), query(query_)
|
2020-07-06 13:57:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockIO InterpreterExternalDDLQuery::execute()
|
|
|
|
{
|
|
|
|
const ASTExternalDDLQuery & external_ddl_query = query->as<ASTExternalDDLQuery &>();
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
if (getContext()->getClientInfo().query_kind != ClientInfo::QueryKind::SECONDARY_QUERY)
|
2020-07-21 09:56:55 +00:00
|
|
|
throw Exception("Cannot parse and execute EXTERNAL DDL FROM.", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
|
2020-07-06 13:57:45 +00:00
|
|
|
if (external_ddl_query.from->name == "MySQL")
|
|
|
|
{
|
|
|
|
#ifdef USE_MYSQL
|
|
|
|
const ASTs & arguments = external_ddl_query.from->arguments->children;
|
|
|
|
|
|
|
|
if (arguments.size() != 2 || !arguments[0]->as<ASTIdentifier>() || !arguments[1]->as<ASTIdentifier>())
|
|
|
|
throw Exception("MySQL External require two identifier arguments.", ErrorCodes::BAD_ARGUMENTS);
|
|
|
|
|
|
|
|
if (external_ddl_query.external_ddl->as<ASTDropQuery>())
|
|
|
|
return MySQLInterpreter::InterpreterMySQLDropQuery(
|
2021-04-10 23:33:54 +00:00
|
|
|
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
|
2020-07-06 13:57:45 +00:00
|
|
|
getIdentifierName(arguments[1])).execute();
|
|
|
|
else if (external_ddl_query.external_ddl->as<ASTRenameQuery>())
|
|
|
|
return MySQLInterpreter::InterpreterMySQLRenameQuery(
|
2021-04-10 23:33:54 +00:00
|
|
|
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
|
2020-07-06 13:57:45 +00:00
|
|
|
getIdentifierName(arguments[1])).execute();
|
2020-07-13 04:16:28 +00:00
|
|
|
else if (external_ddl_query.external_ddl->as<MySQLParser::ASTAlterQuery>())
|
|
|
|
return MySQLInterpreter::InterpreterMySQLAlterQuery(
|
2021-04-10 23:33:54 +00:00
|
|
|
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
|
2020-07-21 09:56:55 +00:00
|
|
|
getIdentifierName(arguments[1])).execute();
|
2020-07-06 13:57:45 +00:00
|
|
|
else if (external_ddl_query.external_ddl->as<MySQLParser::ASTCreateQuery>())
|
|
|
|
return MySQLInterpreter::InterpreterMySQLCreateQuery(
|
2021-04-10 23:33:54 +00:00
|
|
|
external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]),
|
2020-07-21 09:56:55 +00:00
|
|
|
getIdentifierName(arguments[1])).execute();
|
2020-08-06 04:03:27 +00:00
|
|
|
#endif
|
2020-07-06 13:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BlockIO();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|