1 | #include <Parsers/ParserOptimizeQuery.h> |
2 | #include <Parsers/ParserPartition.h> |
3 | #include <Parsers/CommonParsers.h> |
4 | |
5 | #include <Parsers/ASTOptimizeQuery.h> |
6 | #include <Parsers/ASTIdentifier.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | |
13 | bool ParserOptimizeQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) |
14 | { |
15 | ParserKeyword s_optimize_table("OPTIMIZE TABLE" ); |
16 | ParserKeyword s_partition("PARTITION" ); |
17 | ParserKeyword s_final("FINAL" ); |
18 | ParserKeyword s_deduplicate("DEDUPLICATE" ); |
19 | ParserToken s_dot(TokenType::Dot); |
20 | ParserIdentifier name_p; |
21 | ParserPartition partition_p; |
22 | |
23 | ASTPtr database; |
24 | ASTPtr table; |
25 | ASTPtr partition; |
26 | bool final = false; |
27 | bool deduplicate = false; |
28 | String cluster_str; |
29 | |
30 | if (!s_optimize_table.ignore(pos, expected)) |
31 | return false; |
32 | |
33 | if (!name_p.parse(pos, table, expected)) |
34 | return false; |
35 | |
36 | if (s_dot.ignore(pos, expected)) |
37 | { |
38 | database = table; |
39 | if (!name_p.parse(pos, table, expected)) |
40 | return false; |
41 | } |
42 | |
43 | if (ParserKeyword{"ON" }.ignore(pos, expected) && !ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) |
44 | return false; |
45 | |
46 | if (s_partition.ignore(pos, expected)) |
47 | { |
48 | if (!partition_p.parse(pos, partition, expected)) |
49 | return false; |
50 | } |
51 | |
52 | if (s_final.ignore(pos, expected)) |
53 | final = true; |
54 | |
55 | if (s_deduplicate.ignore(pos, expected)) |
56 | deduplicate = true; |
57 | |
58 | auto query = std::make_shared<ASTOptimizeQuery>(); |
59 | node = query; |
60 | |
61 | tryGetIdentifierNameInto(database, query->database); |
62 | tryGetIdentifierNameInto(table, query->table); |
63 | |
64 | query->cluster = cluster_str; |
65 | query->partition = partition; |
66 | query->final = final; |
67 | query->deduplicate = deduplicate; |
68 | |
69 | return true; |
70 | } |
71 | |
72 | |
73 | } |
74 | |