ClickHouse/src/Parsers/ParserExternalDDLQuery.cpp

82 lines
2.6 KiB
C++
Raw Normal View History

2021-10-27 23:10:39 +00:00
#include "config_core.h"
2020-07-01 06:42:22 +00:00
2020-07-06 13:57:45 +00:00
#include <Parsers/ASTExternalDDLQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ParserExternalDDLQuery.h>
#include <Parsers/ParserDropQuery.h>
#include <Parsers/ParserRenameQuery.h>
2021-11-08 11:18:27 +00:00
#if USE_MYSQL
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
{
2021-11-08 11:18:27 +00:00
#if USE_MYSQL
namespace ErrorCodes
{
extern const int MYSQL_SYNTAX_ERROR;
}
#endif
2020-07-06 13:57:45 +00:00
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<ASTExternalDDLQuery>();
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")
{
2021-11-08 11:18:27 +00:00
#if USE_MYSQL
2020-07-06 13:57:45 +00:00
ParserDropQuery p_drop_query;
ParserRenameQuery p_rename_query;
2020-07-13 04:16:28 +00:00
MySQLParser::ParserAlterQuery p_alter_query;
2020-07-06 13:57:45 +00:00
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)
2020-07-13 04:16:28 +00:00
|| p_alter_query.parse(pos, external_ddl_query->external_ddl, expected)
2020-07-06 13:57:45 +00:00
|| 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("Cannot parse MySQL alter query.", ErrorCodes::MYSQL_SYNTAX_ERROR);
if (ParserKeyword("RENAME TABLE").ignore(pos))
throw Exception("Cannot parse MySQL rename query.", ErrorCodes::MYSQL_SYNTAX_ERROR);
if (ParserKeyword("DROP TABLE").ignore(pos) || ParserKeyword("TRUNCATE").ignore(pos))
throw Exception("Cannot parse MySQL drop query.", ErrorCodes::MYSQL_SYNTAX_ERROR);
if (ParserKeyword("CREATE TABLE").ignore(pos) || ParserKeyword("CREATE TEMPORARY TABLE").ignore(pos))
throw Exception("Cannot parse MySQL create query.", ErrorCodes::MYSQL_SYNTAX_ERROR);
}
2020-07-06 13:57:45 +00:00
#endif
}
node = external_ddl_query;
return res;
}
}