#include "config.h" #include #include #include #include #include #include #include #if USE_MYSQL # include # include # include #endif namespace DB { #if USE_MYSQL namespace ErrorCodes { extern const int MYSQL_SYNTAX_ERROR; } #endif bool ParserExternalDDLQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected) { ParserFunction p_function; ParserKeyword s_external("EXTERNAL DDL FROM"); ASTPtr from; auto external_ddl_query = std::make_shared(); if (!s_external.ignore(pos, expected)) return false; if (!p_function.parse(pos, from, expected)) return false; external_ddl_query->set(external_ddl_query->from, from); bool res = false; if (external_ddl_query->from->name == "MySQL") { #if USE_MYSQL MySQLParser::ParserDropQuery p_drop_query; ParserRenameQuery p_rename_query; MySQLParser::ParserAlterQuery p_alter_query; MySQLParser::ParserCreateQuery p_create_query; res = p_create_query.parse(pos, external_ddl_query->external_ddl, expected) || p_drop_query.parse(pos, external_ddl_query->external_ddl, expected) || p_alter_query.parse(pos, external_ddl_query->external_ddl, expected) || p_rename_query.parse(pos, external_ddl_query->external_ddl, expected); if (external_ddl_query->external_ddl) external_ddl_query->children.push_back(external_ddl_query->external_ddl); if (!res) { /// Syntax error is ignored, so we need to convert the error code for parsing failure if (ParserKeyword("ALTER TABLE").ignore(pos)) throw Exception(ErrorCodes::MYSQL_SYNTAX_ERROR, "Cannot parse MySQL alter query."); if (ParserKeyword("RENAME TABLE").ignore(pos)) throw Exception(ErrorCodes::MYSQL_SYNTAX_ERROR, "Cannot parse MySQL rename query."); if (ParserKeyword("DROP TABLE").ignore(pos) || ParserKeyword("TRUNCATE").ignore(pos)) throw Exception(ErrorCodes::MYSQL_SYNTAX_ERROR, "Cannot parse MySQL drop query."); if (ParserKeyword("CREATE TABLE").ignore(pos) || ParserKeyword("CREATE TEMPORARY TABLE").ignore(pos)) throw Exception(ErrorCodes::MYSQL_SYNTAX_ERROR, "Cannot parse MySQL create query."); } #endif } node = external_ddl_query; return res; } }