1#include <Parsers/ASTLiteral.h>
2#include <Parsers/ASTIdentifier.h>
3#include <Parsers/ASTShowTablesQuery.h>
4
5#include <Parsers/CommonParsers.h>
6#include <Parsers/ParserShowTablesQuery.h>
7#include <Parsers/ExpressionElementParsers.h>
8#include <Parsers/ExpressionListParsers.h>
9
10#include <Common/typeid_cast.h>
11
12
13namespace DB
14{
15
16
17bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
18{
19 ParserKeyword s_show("SHOW");
20 ParserKeyword s_temporary("TEMPORARY");
21 ParserKeyword s_tables("TABLES");
22 ParserKeyword s_databases("DATABASES");
23 ParserKeyword s_dictionaries("DICTIONARIES");
24 ParserKeyword s_from("FROM");
25 ParserKeyword s_not("NOT");
26 ParserKeyword s_like("LIKE");
27 ParserKeyword s_limit("LIMIT");
28 ParserStringLiteral like_p;
29 ParserIdentifier name_p;
30 ParserExpressionWithOptionalAlias limit_p(false);
31
32 ASTPtr like;
33 ASTPtr database;
34
35 auto query = std::make_shared<ASTShowTablesQuery>();
36
37 if (!s_show.ignore(pos, expected))
38 return false;
39
40 if (s_databases.ignore(pos))
41 {
42 query->databases = true;
43 }
44 else
45 {
46 if (s_temporary.ignore(pos))
47 query->temporary = true;
48
49 if (!s_tables.ignore(pos, expected))
50 {
51 if (s_dictionaries.ignore(pos, expected))
52 query->dictionaries = true;
53 else
54 return false;
55 }
56
57 if (s_from.ignore(pos, expected))
58 {
59 if (!name_p.parse(pos, database, expected))
60 return false;
61 }
62
63 if (s_not.ignore(pos, expected))
64 query->not_like = true;
65
66 if (s_like.ignore(pos, expected))
67 {
68 if (!like_p.parse(pos, like, expected))
69 return false;
70 }
71 else if (query->not_like)
72 return false;
73
74 if (s_limit.ignore(pos, expected))
75 {
76 if (!limit_p.parse(pos, query->limit_length, expected))
77 return false;
78 }
79 }
80
81 tryGetIdentifierNameInto(database, query->from);
82 if (like)
83 query->like = safeGet<const String &>(like->as<ASTLiteral &>().value);
84
85 node = query;
86
87 return true;
88}
89
90
91}
92