1 | #include <Parsers/ParserShowCreateAccessEntityQuery.h> |
2 | #include <Parsers/ASTShowCreateAccessEntityQuery.h> |
3 | #include <Parsers/CommonParsers.h> |
4 | #include <Parsers/parseIdentifierOrStringLiteral.h> |
5 | #include <Parsers/parseDatabaseAndTableName.h> |
6 | #include <assert.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | bool ParserShowCreateAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) |
12 | { |
13 | if (!ParserKeyword{"SHOW CREATE" }.ignore(pos, expected)) |
14 | return false; |
15 | |
16 | using Kind = ASTShowCreateAccessEntityQuery::Kind; |
17 | Kind kind; |
18 | if (ParserKeyword{"QUOTA" }.ignore(pos, expected)) |
19 | kind = Kind::QUOTA; |
20 | else if (ParserKeyword{"POLICY" }.ignore(pos, expected) || ParserKeyword{"ROW POLICY" }.ignore(pos, expected)) |
21 | kind = Kind::ROW_POLICY; |
22 | else |
23 | return false; |
24 | |
25 | String name; |
26 | bool current_quota = false; |
27 | RowPolicy::FullNameParts row_policy_name; |
28 | |
29 | if (kind == Kind::ROW_POLICY) |
30 | { |
31 | String & database = row_policy_name.database; |
32 | String & table_name = row_policy_name.table_name; |
33 | String & policy_name = row_policy_name.policy_name; |
34 | if (!parseIdentifierOrStringLiteral(pos, expected, policy_name) || !ParserKeyword{"ON" }.ignore(pos, expected) |
35 | || !parseDatabaseAndTableName(pos, expected, database, table_name)) |
36 | return false; |
37 | } |
38 | else |
39 | { |
40 | assert(kind == Kind::QUOTA); |
41 | if (ParserKeyword{"CURRENT" }.ignore(pos, expected)) |
42 | { |
43 | /// SHOW CREATE QUOTA CURRENT |
44 | current_quota = true; |
45 | } |
46 | else if (parseIdentifierOrStringLiteral(pos, expected, name)) |
47 | { |
48 | /// SHOW CREATE QUOTA name |
49 | } |
50 | else |
51 | { |
52 | /// SHOW CREATE QUOTA |
53 | current_quota = true; |
54 | } |
55 | } |
56 | |
57 | auto query = std::make_shared<ASTShowCreateAccessEntityQuery>(kind); |
58 | node = query; |
59 | |
60 | query->name = std::move(name); |
61 | query->current_quota = current_quota; |
62 | query->row_policy_name = std::move(row_policy_name); |
63 | |
64 | return true; |
65 | } |
66 | } |
67 | |