1#pragma once
2
3#include <Parsers/IParserBase.h>
4
5
6namespace DB
7{
8
9
10class ParserArray : public IParserBase
11{
12protected:
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 */
22class ParserParenthesisExpression : public IParserBase
23{
24protected:
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 */
32class ParserSubquery : public IParserBase
33{
34protected:
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 */
42class ParserIdentifier : public IParserBase
43{
44protected:
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 */
52class ParserCompoundIdentifier : public IParserBase
53{
54protected:
55 const char * getName() const { return "compound identifier"; }
56 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
57};
58
59/// Just *
60class ParserAsterisk : public IParserBase
61{
62protected:
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 */
69class ParserQualifiedAsterisk : public IParserBase
70{
71protected:
72 const char * getName() const { return "qualified asterisk"; }
73 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
74};
75
76/** COLUMNS('<regular expression>')
77 */
78class ParserColumnsMatcher : public IParserBase
79{
80protected:
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 */
91class ParserFunction : public IParserBase
92{
93public:
94 ParserFunction(bool allow_function_parameters_ = true) : allow_function_parameters(allow_function_parameters_) {}
95protected:
96 const char * getName() const { return "function"; }
97 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
98 bool allow_function_parameters;
99};
100
101class ParserCodecDeclarationList : public IParserBase
102{
103protected:
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 */
111class ParserCodec : public IParserBase
112{
113protected:
114 const char * getName() const { return "codec"; }
115 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
116};
117
118class ParserCastExpression : public IParserBase
119{
120protected:
121 const char * getName() const override { return "CAST expression"; }
122 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
123};
124
125class ParserSubstringExpression : public IParserBase
126{
127protected:
128 const char * getName() const override { return "SUBSTRING expression"; }
129 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
130};
131
132class ParserTrimExpression : public IParserBase
133{
134protected:
135 const char * getName() const override { return "TRIM expression"; }
136 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
137};
138
139class ParserLeftExpression : public IParserBase
140{
141protected:
142 const char * getName() const override { return "LEFT expression"; }
143 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
144};
145
146class ParserRightExpression : public IParserBase
147{
148protected:
149 const char * getName() const override { return "RIGHT expression"; }
150 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
151};
152
153class ParserExtractExpression : public IParserBase
154{
155protected:
156 const char * getName() const override { return "EXTRACT expression"; }
157 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
158};
159
160class ParserDateAddExpression : public IParserBase
161{
162protected:
163 const char * getName() const override { return "DATE_ADD expression"; }
164 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
165};
166
167class ParserDateDiffExpression : public IParserBase
168{
169protected:
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 */
176class ParserNull : public IParserBase
177{
178protected:
179 const char * getName() const { return "NULL"; }
180 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
181};
182
183
184/** Numeric literal.
185 */
186class ParserNumber : public IParserBase
187{
188protected:
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 */
195class ParserUnsignedInteger : public IParserBase
196{
197protected:
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 */
205class ParserStringLiteral : public IParserBase
206{
207protected:
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 */
219class ParserArrayOfLiterals : public IParserBase
220{
221protected:
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 */
229class ParserLiteral : public IParserBase
230{
231protected:
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 */
239class ParserAlias : public IParserBase
240{
241public:
242 ParserAlias(bool allow_alias_without_as_keyword_)
243 : allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
244private:
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 */
257class ParserSubstitution : public IParserBase
258{
259protected:
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 */
267class ParserExpressionElement : public IParserBase
268{
269protected:
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 */
277class ParserWithOptionalAlias : public IParserBase
278{
279public:
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_) {}
282protected:
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 */
296class ParserOrderByElement : public IParserBase
297{
298protected:
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 */
306class ParserFunctionWithKeyValueArguments : public IParserBase
307{
308protected:
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 */
316class ParserIdentifierWithOptionalParameters : public IParserBase
317{
318protected:
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 */
326class ParserTTLElement : public IParserBase
327{
328protected:
329 const char * getName() const { return "element of TTL expression"; }
330 bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
331};
332
333}
334