1#include <Parsers/ParserCheckQuery.h>
2#include <Parsers/CommonParsers.h>
3#include <Parsers/ASTIdentifier.h>
4#include <Parsers/ExpressionElementParsers.h>
5#include <Parsers/ASTCheckQuery.h>
6#include <Parsers/ParserPartition.h>
7
8
9namespace DB
10{
11
12bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
13{
14 ParserKeyword s_check_table("CHECK TABLE");
15 ParserKeyword s_partition("PARTITION");
16 ParserToken s_dot(TokenType::Dot);
17
18 ParserIdentifier table_parser;
19 ParserPartition partition_parser;
20
21 ASTPtr table;
22 ASTPtr database;
23
24 if (!s_check_table.ignore(pos, expected))
25 return false;
26 if (!table_parser.parse(pos, database, expected))
27 return false;
28
29 auto query = std::make_shared<ASTCheckQuery>();
30 if (s_dot.ignore(pos))
31 {
32 if (!table_parser.parse(pos, table, expected))
33 return false;
34
35 tryGetIdentifierNameInto(database, query->database);
36 tryGetIdentifierNameInto(table, query->table);
37 }
38 else
39 {
40 table = database;
41 tryGetIdentifierNameInto(table, query->table);
42 }
43
44 if (s_partition.ignore(pos, expected))
45 {
46 if (!partition_parser.parse(pos, query->partition, expected))
47 return false;
48 }
49
50 node = query;
51 return true;
52}
53
54}
55