1 | #pragma once |
2 | |
3 | #include <Parsers/IParserBase.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | |
10 | class ParserArray : public IParserBase |
11 | { |
12 | protected: |
13 | const char * getName() const { return "array" ; } |
14 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
15 | }; |
16 | |
17 | |
18 | /** If in parenthesis an expression from one element - returns this element in `node`; |
19 | * or if there is a SELECT subquery in parenthesis, then this subquery returned in `node`; |
20 | * otherwise returns `tuple` function from the contents of brackets. |
21 | */ |
22 | class ParserParenthesisExpression : public IParserBase |
23 | { |
24 | protected: |
25 | const char * getName() const { return "parenthesized expression" ; } |
26 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
27 | }; |
28 | |
29 | |
30 | /** The SELECT subquery is in parenthesis. |
31 | */ |
32 | class ParserSubquery : public IParserBase |
33 | { |
34 | protected: |
35 | const char * getName() const { return "SELECT subquery" ; } |
36 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
37 | }; |
38 | |
39 | |
40 | /** An identifier, for example, x_yz123 or `something special` |
41 | */ |
42 | class ParserIdentifier : public IParserBase |
43 | { |
44 | protected: |
45 | const char * getName() const { return "identifier" ; } |
46 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
47 | }; |
48 | |
49 | |
50 | /** An identifier, possibly containing a dot, for example, x_yz123 or `something special` or Hits.EventTime |
51 | */ |
52 | class ParserCompoundIdentifier : public IParserBase |
53 | { |
54 | protected: |
55 | const char * getName() const { return "compound identifier" ; } |
56 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
57 | }; |
58 | |
59 | /// Just * |
60 | class ParserAsterisk : public IParserBase |
61 | { |
62 | protected: |
63 | const char * getName() const { return "asterisk" ; } |
64 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
65 | }; |
66 | |
67 | /** Something like t.* or db.table.* |
68 | */ |
69 | class ParserQualifiedAsterisk : public IParserBase |
70 | { |
71 | protected: |
72 | const char * getName() const { return "qualified asterisk" ; } |
73 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
74 | }; |
75 | |
76 | /** COLUMNS('<regular expression>') |
77 | */ |
78 | class ParserColumnsMatcher : public IParserBase |
79 | { |
80 | protected: |
81 | const char * getName() const { return "COLUMNS matcher" ; } |
82 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
83 | }; |
84 | |
85 | /** A function, for example, f(x, y + 1, g(z)). |
86 | * Or an aggregate function: sum(x + f(y)), corr(x, y). The syntax is the same as the usual function. |
87 | * Or a parametric aggregate function: quantile(0.9)(x + y). |
88 | * Syntax - two pairs of parentheses instead of one. The first is for parameters, the second for arguments. |
89 | * For functions, the DISTINCT modifier can be specified, for example, count(DISTINCT x, y). |
90 | */ |
91 | class ParserFunction : public IParserBase |
92 | { |
93 | public: |
94 | ParserFunction(bool allow_function_parameters_ = true) : allow_function_parameters(allow_function_parameters_) {} |
95 | protected: |
96 | const char * getName() const { return "function" ; } |
97 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
98 | bool allow_function_parameters; |
99 | }; |
100 | |
101 | class ParserCodecDeclarationList : public IParserBase |
102 | { |
103 | protected: |
104 | const char * getName() const { return "codec declaration list" ; } |
105 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
106 | }; |
107 | |
108 | /** Parse compression codec |
109 | * CODEC(ZSTD(2)) |
110 | */ |
111 | class ParserCodec : public IParserBase |
112 | { |
113 | protected: |
114 | const char * getName() const { return "codec" ; } |
115 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
116 | }; |
117 | |
118 | class ParserCastExpression : public IParserBase |
119 | { |
120 | protected: |
121 | const char * getName() const override { return "CAST expression" ; } |
122 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
123 | }; |
124 | |
125 | class ParserSubstringExpression : public IParserBase |
126 | { |
127 | protected: |
128 | const char * getName() const override { return "SUBSTRING expression" ; } |
129 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
130 | }; |
131 | |
132 | class ParserTrimExpression : public IParserBase |
133 | { |
134 | protected: |
135 | const char * getName() const override { return "TRIM expression" ; } |
136 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
137 | }; |
138 | |
139 | class ParserLeftExpression : public IParserBase |
140 | { |
141 | protected: |
142 | const char * getName() const override { return "LEFT expression" ; } |
143 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
144 | }; |
145 | |
146 | class ParserRightExpression : public IParserBase |
147 | { |
148 | protected: |
149 | const char * getName() const override { return "RIGHT expression" ; } |
150 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
151 | }; |
152 | |
153 | class : public IParserBase |
154 | { |
155 | protected: |
156 | const char * () const override { return "EXTRACT expression" ; } |
157 | bool (Pos & pos, ASTPtr & node, Expected & expected) override; |
158 | }; |
159 | |
160 | class ParserDateAddExpression : public IParserBase |
161 | { |
162 | protected: |
163 | const char * getName() const override { return "DATE_ADD expression" ; } |
164 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
165 | }; |
166 | |
167 | class ParserDateDiffExpression : public IParserBase |
168 | { |
169 | protected: |
170 | const char * getName() const override { return "DATE_DIFF expression" ; } |
171 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
172 | }; |
173 | |
174 | /** NULL literal. |
175 | */ |
176 | class ParserNull : public IParserBase |
177 | { |
178 | protected: |
179 | const char * getName() const { return "NULL" ; } |
180 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
181 | }; |
182 | |
183 | |
184 | /** Numeric literal. |
185 | */ |
186 | class ParserNumber : public IParserBase |
187 | { |
188 | protected: |
189 | const char * getName() const { return "number" ; } |
190 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
191 | }; |
192 | |
193 | /** Unsigned integer, used in right hand side of tuple access operator (x.1). |
194 | */ |
195 | class ParserUnsignedInteger : public IParserBase |
196 | { |
197 | protected: |
198 | const char * getName() const { return "unsigned integer" ; } |
199 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
200 | }; |
201 | |
202 | |
203 | /** String in single quotes. |
204 | */ |
205 | class ParserStringLiteral : public IParserBase |
206 | { |
207 | protected: |
208 | const char * getName() const { return "string literal" ; } |
209 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
210 | }; |
211 | |
212 | |
213 | /** An array of literals. |
214 | * Arrays can also be parsed as an application of [] operator. |
215 | * But parsing the whole array as a whole constant seriously speeds up the analysis of expressions in the case of very large arrays. |
216 | * We try to parse the array as an array of literals first (fast path), |
217 | * and if it did not work out (when the array consists of complex expressions) - parse as an application of [] operator (slow path). |
218 | */ |
219 | class ParserArrayOfLiterals : public IParserBase |
220 | { |
221 | protected: |
222 | const char * getName() const { return "array" ; } |
223 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
224 | }; |
225 | |
226 | |
227 | /** The literal is one of: NULL, UInt64, Int64, Float64, String. |
228 | */ |
229 | class ParserLiteral : public IParserBase |
230 | { |
231 | protected: |
232 | const char * getName() const { return "literal" ; } |
233 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
234 | }; |
235 | |
236 | |
237 | /** The alias is the identifier before which `AS` comes. For example: AS x_yz123. |
238 | */ |
239 | class ParserAlias : public IParserBase |
240 | { |
241 | public: |
242 | ParserAlias(bool allow_alias_without_as_keyword_) |
243 | : allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {} |
244 | private: |
245 | static const char * restricted_keywords[]; |
246 | |
247 | bool allow_alias_without_as_keyword; |
248 | |
249 | const char * getName() const { return "alias" ; } |
250 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
251 | }; |
252 | |
253 | |
254 | /** Prepared statements. |
255 | * Parse query with parameter expression {name:type}. |
256 | */ |
257 | class ParserSubstitution : public IParserBase |
258 | { |
259 | protected: |
260 | const char * getName() const { return "substitution" ; } |
261 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
262 | }; |
263 | |
264 | |
265 | /** The expression element is one of: an expression in parentheses, an array, a literal, a function, an identifier, an asterisk. |
266 | */ |
267 | class ParserExpressionElement : public IParserBase |
268 | { |
269 | protected: |
270 | const char * getName() const { return "element of expression" ; } |
271 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
272 | }; |
273 | |
274 | |
275 | /** An expression element, possibly with an alias, if appropriate. |
276 | */ |
277 | class ParserWithOptionalAlias : public IParserBase |
278 | { |
279 | public: |
280 | ParserWithOptionalAlias(ParserPtr && elem_parser_, bool allow_alias_without_as_keyword_) |
281 | : elem_parser(std::move(elem_parser_)), allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {} |
282 | protected: |
283 | ParserPtr elem_parser; |
284 | bool allow_alias_without_as_keyword; |
285 | |
286 | const char * getName() const { return "element of expression with optional alias" ; } |
287 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
288 | }; |
289 | |
290 | |
291 | /** Element of ORDER BY expression - same as expression element, but in addition, ASC[ENDING] | DESC[ENDING] could be specified |
292 | * and optionally, NULLS LAST|FIRST |
293 | * and optionally, COLLATE 'locale'. |
294 | * and optionally, WITH FILL [FROM x] [TO y] [STEP z] |
295 | */ |
296 | class ParserOrderByElement : public IParserBase |
297 | { |
298 | protected: |
299 | const char * getName() const { return "element of ORDER BY expression" ; } |
300 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
301 | }; |
302 | |
303 | /** Parser for function with arguments like KEY VALUE (space separated) |
304 | * no commas alowed, just space-separated pairs. |
305 | */ |
306 | class ParserFunctionWithKeyValueArguments : public IParserBase |
307 | { |
308 | protected: |
309 | const char * getName() const override { return "function with key-value arguments" ; } |
310 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; |
311 | }; |
312 | |
313 | /** Data type or table engine, possibly with parameters. For example, UInt8 or see examples from ParserIdentifierWithParameters |
314 | * Parse result is ASTFunction, with or without arguments. |
315 | */ |
316 | class ParserIdentifierWithOptionalParameters : public IParserBase |
317 | { |
318 | protected: |
319 | const char * getName() const { return "identifier with optional parameters" ; } |
320 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
321 | }; |
322 | |
323 | /** Element of TTL expression - same as expression element, but in addition, |
324 | * TO DISK 'xxx' | TO VOLUME 'xxx' | DELETE could be specified |
325 | */ |
326 | class ParserTTLElement : public IParserBase |
327 | { |
328 | protected: |
329 | const char * getName() const { return "element of TTL expression" ; } |
330 | bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); |
331 | }; |
332 | |
333 | } |
334 | |