ClickHouse/src/Parsers/ParserExternalDDLQuery.cpp
Alexander Tokmakov 70d1adfe4b
Better formatting for exception messages (#45449)
* save format string for NetException

* format exceptions

* format exceptions 2

* format exceptions 3

* format exceptions 4

* format exceptions 5

* format exceptions 6

* fix

* format exceptions 7

* format exceptions 8

* Update MergeTreeIndexGin.cpp

* Update AggregateFunctionMap.cpp

* Update AggregateFunctionMap.cpp

* fix
2023-01-24 00:13:58 +03:00

84 lines
2.7 KiB
C++

#include "config.h"
#include <Parsers/ASTExternalDDLQuery.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/ParserDropQuery.h>
#include <Parsers/ParserExternalDDLQuery.h>
#include <Parsers/ParserRenameQuery.h>
#if USE_MYSQL
# include <Parsers/MySQL/ASTAlterQuery.h>
# include <Parsers/MySQL/ASTCreateQuery.h>
# include <Parsers/MySQL/ASTDropQuery.h>
#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<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")
{
#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;
}
}