1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#include <Parsers/ASTIdentifier_fwd.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTShowTablesQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserShowTablesQuery.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/parseIdentifierOrStringLiteral.h>
#include <Common/typeid_cast.h>
namespace DB
{
bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserKeyword s_show("SHOW");
ParserKeyword s_full("FULL");
ParserKeyword s_temporary("TEMPORARY");
ParserKeyword s_tables("TABLES");
ParserKeyword s_databases("DATABASES");
ParserKeyword s_clusters("CLUSTERS");
ParserKeyword s_cluster("CLUSTER");
ParserKeyword s_dictionaries("DICTIONARIES");
ParserKeyword s_caches("FILESYSTEM CACHES");
ParserKeyword s_settings("SETTINGS");
ParserKeyword s_changed("CHANGED");
ParserKeyword s_from("FROM");
ParserKeyword s_in("IN");
ParserKeyword s_not("NOT");
ParserKeyword s_like("LIKE");
ParserKeyword s_ilike("ILIKE");
ParserKeyword s_where("WHERE");
ParserKeyword s_limit("LIMIT");
ParserStringLiteral like_p;
ParserIdentifier name_p(true);
ParserExpressionWithOptionalAlias exp_elem(false);
ASTPtr like;
ASTPtr database;
auto query = std::make_shared<ASTShowTablesQuery>();
if (!s_show.ignore(pos, expected))
return false;
if (s_full.ignore(pos, expected))
{
query->full = true;
}
if (s_databases.ignore(pos, expected))
{
query->databases = true;
if (s_not.ignore(pos, expected))
query->not_like = true;
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
{
if (insensitive)
query->case_insensitive_like = true;
if (!like_p.parse(pos, like, expected))
return false;
}
else if (query->not_like)
return false;
if (s_limit.ignore(pos, expected))
{
if (!exp_elem.parse(pos, query->limit_length, expected))
return false;
}
}
else if (s_clusters.ignore(pos, expected))
{
query->clusters = true;
if (s_not.ignore(pos, expected))
query->not_like = true;
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
{
if (insensitive)
query->case_insensitive_like = true;
if (!like_p.parse(pos, like, expected))
return false;
}
else if (query->not_like)
return false;
if (s_limit.ignore(pos, expected))
{
if (!exp_elem.parse(pos, query->limit_length, expected))
return false;
}
}
else if (s_caches.ignore(pos, expected))
{
query->caches = true;
}
else if (s_cluster.ignore(pos, expected))
{
query->cluster = true;
String cluster_str;
if (!parseIdentifierOrStringLiteral(pos, expected, cluster_str))
return false;
query->cluster_str = std::move(cluster_str);
}
else if (bool changed = s_changed.ignore(pos, expected); changed || s_settings.ignore(pos, expected))
{
query->m_settings = true;
if (changed)
{
query->changed = true;
if (!s_settings.ignore(pos, expected))
return false;
}
/// Not expected due to "SHOW SETTINGS PROFILES"
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
{
if (insensitive)
query->case_insensitive_like = true;
if (!like_p.parse(pos, like, expected))
return false;
}
else
return false;
}
else
{
if (s_temporary.ignore(pos))
query->temporary = true;
if (!s_tables.ignore(pos, expected))
{
if (s_dictionaries.ignore(pos, expected))
query->dictionaries = true;
else
return false;
}
if (s_from.ignore(pos, expected) || s_in.ignore(pos, expected))
if (!name_p.parse(pos, database, expected))
return false;
if (s_not.ignore(pos, expected))
query->not_like = true;
if (bool insensitive = s_ilike.ignore(pos, expected); insensitive || s_like.ignore(pos, expected))
{
if (insensitive)
query->case_insensitive_like = true;
if (!like_p.parse(pos, like, expected))
return false;
}
else if (query->not_like)
return false;
else if (s_where.ignore(pos, expected))
if (!exp_elem.parse(pos, query->where_expression, expected))
return false;
if (s_limit.ignore(pos, expected))
if (!exp_elem.parse(pos, query->limit_length, expected))
return false;
}
query->set(query->from, database);
if (like)
query->like = like->as<ASTLiteral &>().value.safeGet<const String &>();
node = query;
return true;
}
}
|