ClickHouse/dbms/src/Parsers/ParserCheckQuery.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

#include <Parsers/ParserCheckQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ASTCheckQuery.h>
2014-08-05 10:52:06 +00:00
#include <Common/typeid_cast.h>
2016-11-20 12:43:20 +00:00
namespace DB
{
2014-08-05 10:52:06 +00:00
bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
2014-08-05 10:52:06 +00:00
{
Pos begin = pos;
ParserKeyword s_check_table("CHECK TABLE");
ParserToken s_dot(TokenType::Dot);
2014-08-05 10:52:06 +00:00
ParserIdentifier table_parser;
2014-08-05 10:52:06 +00:00
ASTPtr table;
ASTPtr database;
2014-08-05 10:52:06 +00:00
if (!s_check_table.ignore(pos, expected))
return false;
if (!table_parser.parse(pos, database, expected))
return false;
2014-08-05 10:52:06 +00:00
if (s_dot.ignore(pos))
{
if (!table_parser.parse(pos, table, expected))
return false;
2014-08-05 10:52:06 +00:00
auto query = std::make_shared<ASTCheckQuery>(StringRange(begin, pos));
query->database = typeid_cast<const ASTIdentifier &>(*database).name;
query->table = typeid_cast<const ASTIdentifier &>(*table).name;
node = query;
}
else
{
table = database;
auto query = std::make_shared<ASTCheckQuery>(StringRange(begin, pos));
query->table = typeid_cast<const ASTIdentifier &>(*table).name;
node = query;
}
2014-08-05 10:52:06 +00:00
return true;
2014-08-05 10:52:06 +00:00
}
2016-11-20 12:43:20 +00:00
}