#include "config.h" #include #include #include #include #include #include #include #include #if USE_MYSQL # include # include # include # include #endif namespace DB { namespace ErrorCodes { extern const int SYNTAX_ERROR; extern const int BAD_ARGUMENTS; } InterpreterExternalDDLQuery::InterpreterExternalDDLQuery(const ASTPtr & query_, ContextMutablePtr context_) : WithMutableContext(context_), query(query_) { } BlockIO InterpreterExternalDDLQuery::execute() { const ASTExternalDDLQuery & external_ddl_query = query->as(); if (getContext()->getClientInfo().query_kind != ClientInfo::QueryKind::SECONDARY_QUERY) throw Exception(ErrorCodes::SYNTAX_ERROR, "Cannot parse and execute EXTERNAL DDL FROM."); if (external_ddl_query.from->name == "MySQL") { #if USE_MYSQL const ASTs & arguments = external_ddl_query.from->arguments->children; if (arguments.size() != 2 || !arguments[0]->as() || !arguments[1]->as()) throw Exception(ErrorCodes::BAD_ARGUMENTS, "MySQL External require two identifier arguments."); if (external_ddl_query.external_ddl->as()) return MySQLInterpreter::InterpreterMySQLDropQuery( external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]), getIdentifierName(arguments[1])).execute(); else if (external_ddl_query.external_ddl->as()) return MySQLInterpreter::InterpreterMySQLRenameQuery( external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]), getIdentifierName(arguments[1])).execute(); else if (external_ddl_query.external_ddl->as()) return MySQLInterpreter::InterpreterMySQLAlterQuery( external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]), getIdentifierName(arguments[1])).execute(); else if (external_ddl_query.external_ddl->as()) return MySQLInterpreter::InterpreterMySQLCreateQuery( external_ddl_query.external_ddl, getContext(), getIdentifierName(arguments[0]), getIdentifierName(arguments[1])).execute(); #endif } return BlockIO(); } void registerInterpreterExternalDDLQuery(InterpreterFactory & factory) { auto create_fn = [] (const InterpreterFactory::Arguments & args) { return std::make_unique(args.query, args.context); }; factory.registerInterpreter("InterpreterExternalDDLQuery", create_fn); } }