1 | #include <Parsers/ASTIdentifier.h> |
2 | #include <Parsers/TablePropertiesQueriesASTs.h> |
3 | |
4 | #include <Parsers/CommonParsers.h> |
5 | #include <Parsers/ParserTablePropertiesQuery.h> |
6 | |
7 | #include <Common/typeid_cast.h> |
8 | |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | |
14 | bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) |
15 | { |
16 | ParserKeyword s_exists("EXISTS" ); |
17 | ParserKeyword s_temporary("TEMPORARY" ); |
18 | ParserKeyword s_describe("DESCRIBE" ); |
19 | ParserKeyword s_desc("DESC" ); |
20 | ParserKeyword s_show("SHOW" ); |
21 | ParserKeyword s_create("CREATE" ); |
22 | ParserKeyword s_database("DATABASE" ); |
23 | ParserKeyword s_table("TABLE" ); |
24 | ParserKeyword s_dictionary("DICTIONARY" ); |
25 | ParserToken s_dot(TokenType::Dot); |
26 | ParserIdentifier name_p; |
27 | |
28 | ASTPtr database; |
29 | ASTPtr table; |
30 | std::shared_ptr<ASTQueryWithTableAndOutput> query; |
31 | |
32 | bool parse_only_database_name = false; |
33 | |
34 | bool temporary = false; |
35 | if (s_exists.ignore(pos, expected)) |
36 | { |
37 | if (s_temporary.ignore(pos, expected)) |
38 | temporary = true; |
39 | |
40 | if (s_table.checkWithoutMoving(pos, expected)) |
41 | query = std::make_shared<ASTExistsTableQuery>(); |
42 | else if (s_dictionary.checkWithoutMoving(pos, expected)) |
43 | query = std::make_shared<ASTExistsDictionaryQuery>(); |
44 | else |
45 | query = std::make_shared<ASTExistsTableQuery>(); |
46 | } |
47 | else if (s_show.ignore(pos, expected)) |
48 | { |
49 | if (!s_create.ignore(pos, expected)) |
50 | return false; |
51 | |
52 | if (s_database.ignore(pos, expected)) |
53 | { |
54 | parse_only_database_name = true; |
55 | query = std::make_shared<ASTShowCreateDatabaseQuery>(); |
56 | } |
57 | else if (s_dictionary.checkWithoutMoving(pos, expected)) |
58 | query = std::make_shared<ASTShowCreateDictionaryQuery>(); |
59 | else |
60 | query = std::make_shared<ASTShowCreateTableQuery>(); |
61 | } |
62 | else |
63 | { |
64 | return false; |
65 | } |
66 | |
67 | if (parse_only_database_name) |
68 | { |
69 | if (!name_p.parse(pos, database, expected)) |
70 | return false; |
71 | } |
72 | else |
73 | { |
74 | if (temporary || s_temporary.ignore(pos, expected)) |
75 | query->temporary = true; |
76 | |
77 | if (!s_table.ignore(pos, expected)) |
78 | s_dictionary.ignore(pos, expected); |
79 | |
80 | if (!name_p.parse(pos, table, expected)) |
81 | return false; |
82 | |
83 | if (s_dot.ignore(pos, expected)) |
84 | { |
85 | database = table; |
86 | if (!name_p.parse(pos, table, expected)) |
87 | return false; |
88 | } |
89 | } |
90 | |
91 | tryGetIdentifierNameInto(database, query->database); |
92 | tryGetIdentifierNameInto(table, query->table); |
93 | |
94 | node = query; |
95 | |
96 | return true; |
97 | } |
98 | |
99 | |
100 | } |
101 | |