2012-06-18 06:19:13 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTRenameQuery.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/CommonParsers.h>
|
|
|
|
#include <DB/Parsers/ParserRenameQuery.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// Парсит database.table или table.
|
2014-06-12 00:48:56 +00:00
|
|
|
static bool parseDatabaseAndTable(ASTRenameQuery::Table & db_and_table, IParser::Pos & pos, IParser::Pos end, Expected & expected)
|
2012-06-18 06:19:13 +00:00
|
|
|
{
|
|
|
|
ParserIdentifier name_p;
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_dot(".");
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-06-18 06:19:13 +00:00
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!name_p.parse(pos, end, table, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (s_dot.ignore(pos, end, expected))
|
|
|
|
{
|
|
|
|
database = table;
|
|
|
|
if (!name_p.parse(pos, end, table, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
}
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
db_and_table.database = database ? typeid_cast<const ASTIdentifier &>(*database).name : "";
|
|
|
|
db_and_table.table = typeid_cast<const ASTIdentifier &>(*table).name;
|
2012-06-18 06:19:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2014-06-12 00:48:56 +00:00
|
|
|
bool ParserRenameQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected & expected)
|
2012-06-18 06:19:13 +00:00
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
|
|
|
|
ParserWhiteSpaceOrComments ws;
|
|
|
|
ParserString s_rename("RENAME", true, true);
|
|
|
|
ParserString s_table("TABLE", true, true);
|
|
|
|
ParserString s_to("TO", true, true);
|
|
|
|
ParserString s_comma(",");
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-06-18 06:19:13 +00:00
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!s_rename.ignore(pos, end, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
if (!s_table.ignore(pos, end, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ASTRenameQuery::Elements elements;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
ws.ignore(pos, end);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-06-18 06:19:13 +00:00
|
|
|
if (!elements.empty() && !s_comma.ignore(pos, end))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ws.ignore(pos, end);
|
|
|
|
|
|
|
|
elements.push_back(ASTRenameQuery::Element());
|
|
|
|
|
|
|
|
if (!parseDatabaseAndTable(elements.back().from, pos, end, expected)
|
|
|
|
|| !s_to.ignore(pos, end)
|
|
|
|
|| !parseDatabaseAndTable(elements.back().to, pos, end, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTRenameQuery * query = new ASTRenameQuery(StringRange(begin, pos));
|
|
|
|
node = query;
|
|
|
|
|
|
|
|
query->elements = elements;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|