2011-09-04 05:14:52 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2020-03-19 01:15:01 +00:00
|
|
|
#include <Core/Field.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IParserBase.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
class ParserArray : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "array"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** If in parenthesis an expression from one element - returns this element in `node`;
|
|
|
|
* or if there is a SELECT subquery in parenthesis, then this subquery returned in `node`;
|
|
|
|
* otherwise returns `tuple` function from the contents of brackets.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserParenthesisExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "parenthesized expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** The SELECT subquery is in parenthesis.
|
2012-08-22 18:46:09 +00:00
|
|
|
*/
|
|
|
|
class ParserSubquery : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "SELECT subquery"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2012-08-22 18:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** An identifier, for example, x_yz123 or `something special`
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserIdentifier : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "identifier"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-02-04 22:37:04 +00:00
|
|
|
class ParserBareWord : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "bare word"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** An identifier, possibly containing a dot, for example, x_yz123 or `something special` or Hits.EventTime
|
2013-07-16 15:26:35 +00:00
|
|
|
*/
|
|
|
|
class ParserCompoundIdentifier : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "compound identifier"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2013-07-16 15:26:35 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:23:27 +00:00
|
|
|
/// Just *
|
|
|
|
class ParserAsterisk : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "asterisk"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2017-01-04 11:23:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Something like t.* or db.table.*
|
|
|
|
*/
|
|
|
|
class ParserQualifiedAsterisk : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "qualified asterisk"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2017-01-04 11:23:27 +00:00
|
|
|
};
|
|
|
|
|
2019-07-16 20:05:00 +00:00
|
|
|
/** COLUMNS('<regular expression>')
|
2019-07-12 11:17:38 +00:00
|
|
|
*/
|
2019-07-21 17:03:58 +00:00
|
|
|
class ParserColumnsMatcher : public IParserBase
|
2019-07-12 11:17:38 +00:00
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "COLUMNS matcher"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2019-07-12 11:17:38 +00:00
|
|
|
};
|
2017-01-04 11:23:27 +00:00
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** A function, for example, f(x, y + 1, g(z)).
|
|
|
|
* Or an aggregate function: sum(x + f(y)), corr(x, y). The syntax is the same as the usual function.
|
|
|
|
* Or a parametric aggregate function: quantile(0.9)(x + y).
|
|
|
|
* Syntax - two pairs of parentheses instead of one. The first is for parameters, the second for arguments.
|
|
|
|
* For functions, the DISTINCT modifier can be specified, for example, count(DISTINCT x, y).
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserFunction : public IParserBase
|
|
|
|
{
|
2019-11-18 16:49:23 +00:00
|
|
|
public:
|
|
|
|
ParserFunction(bool allow_function_parameters_ = true) : allow_function_parameters(allow_function_parameters_) {}
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "function"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2019-11-18 16:49:23 +00:00
|
|
|
bool allow_function_parameters;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2018-12-13 15:26:28 +00:00
|
|
|
class ParserCodecDeclarationList : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "codec declaration list"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2018-12-13 15:26:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Parse compression codec
|
|
|
|
* CODEC(ZSTD(2))
|
|
|
|
*/
|
|
|
|
class ParserCodec : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "codec"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2018-12-13 15:26:28 +00:00
|
|
|
};
|
|
|
|
|
2015-12-24 17:14:10 +00:00
|
|
|
class ParserCastExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2018-06-07 20:25:38 +00:00
|
|
|
const char * getName() const override { return "CAST expression"; }
|
2017-07-10 03:28:12 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2015-12-24 17:14:10 +00:00
|
|
|
};
|
|
|
|
|
2018-12-10 12:54:02 +00:00
|
|
|
class ParserSubstringExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "SUBSTRING expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2018-12-13 11:50:37 +00:00
|
|
|
class ParserTrimExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "TRIM expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2018-12-13 09:34:12 +00:00
|
|
|
class ParserLeftExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "LEFT expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParserRightExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "RIGHT expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2018-04-13 19:35:08 +00:00
|
|
|
class ParserExtractExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2018-06-07 20:25:38 +00:00
|
|
|
const char * getName() const override { return "EXTRACT expression"; }
|
2018-04-13 19:35:08 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2018-12-19 11:37:14 +00:00
|
|
|
class ParserDateAddExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "DATE_ADD expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2018-12-18 14:40:30 +00:00
|
|
|
class ParserDateDiffExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "DATE_DIFF expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-01-23 15:55:56 +00:00
|
|
|
/** NULL literal.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserNull : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "NULL"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-23 15:55:56 +00:00
|
|
|
/** Numeric literal.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserNumber : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "number"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2017-01-23 15:55:56 +00:00
|
|
|
/** Unsigned integer, used in right hand side of tuple access operator (x.1).
|
2015-11-07 23:18:39 +00:00
|
|
|
*/
|
|
|
|
class ParserUnsignedInteger : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "unsigned integer"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2015-11-07 23:18:39 +00:00
|
|
|
};
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-01-23 15:55:56 +00:00
|
|
|
/** String in single quotes.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserStringLiteral : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "string literal"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2015-06-29 04:54:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-19 01:15:01 +00:00
|
|
|
/** An array or tuple of literals.
|
|
|
|
* Arrays can also be parsed as an application of [] operator and tuples as an application of 'tuple' function.
|
|
|
|
* But parsing the whole array/tuple as a whole constant seriously speeds up the analysis of expressions in the case of very large collection.
|
|
|
|
* We try to parse the array or tuple as a collection of literals first (fast path),
|
|
|
|
* and if it did not work out (when the collection consists of complex expressions) -
|
|
|
|
* parse as an application of [] operator or 'tuple' function (slow path).
|
2015-06-29 04:54:52 +00:00
|
|
|
*/
|
2020-03-19 01:15:01 +00:00
|
|
|
template <typename Collection>
|
|
|
|
class ParserCollectionOfLiterals : public IParserBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParserCollectionOfLiterals(TokenType opening_bracket_, TokenType closing_bracket_)
|
|
|
|
: opening_bracket(opening_bracket_), closing_bracket(closing_bracket_) {}
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "collection of literals"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
private:
|
|
|
|
TokenType opening_bracket;
|
|
|
|
TokenType closing_bracket;
|
|
|
|
};
|
|
|
|
|
2020-03-24 12:55:35 +00:00
|
|
|
/// A tuple of literals with same type.
|
2020-03-19 01:15:01 +00:00
|
|
|
class ParserTupleOfLiterals : public IParserBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParserCollectionOfLiterals<Tuple> tuple_parser{TokenType::OpeningRoundBracket, TokenType::ClosingRoundBracket};
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "tuple"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
|
|
|
{
|
|
|
|
return tuple_parser.parse(pos, node, expected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-29 04:54:52 +00:00
|
|
|
class ParserArrayOfLiterals : public IParserBase
|
|
|
|
{
|
2020-03-19 01:15:01 +00:00
|
|
|
public:
|
|
|
|
ParserCollectionOfLiterals<Array> array_parser{TokenType::OpeningSquareBracket, TokenType::ClosingSquareBracket};
|
2015-06-29 04:54:52 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "array"; }
|
2020-03-19 01:15:01 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
|
|
|
{
|
|
|
|
return array_parser.parse(pos, node, expected);
|
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** The literal is one of: NULL, UInt64, Int64, Float64, String.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserLiteral : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "literal"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** The alias is the identifier before which `AS` comes. For example: AS x_yz123.
|
2011-11-06 04:21:09 +00:00
|
|
|
*/
|
2018-06-07 20:25:38 +00:00
|
|
|
class ParserAlias : public IParserBase
|
2011-11-06 04:21:09 +00:00
|
|
|
{
|
2015-11-08 00:28:12 +00:00
|
|
|
public:
|
2018-06-07 20:25:38 +00:00
|
|
|
ParserAlias(bool allow_alias_without_as_keyword_)
|
2017-04-01 07:20:54 +00:00
|
|
|
: allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
|
2018-06-07 20:25:38 +00:00
|
|
|
private:
|
|
|
|
static const char * restricted_keywords[];
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool allow_alias_without_as_keyword;
|
2015-11-08 00:28:12 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "alias"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2011-11-06 04:21:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-25 13:43:52 +00:00
|
|
|
/** Prepared statements.
|
2019-05-18 21:07:23 +00:00
|
|
|
* Parse query with parameter expression {name:type}.
|
|
|
|
*/
|
2019-05-25 13:43:52 +00:00
|
|
|
class ParserSubstitution : public IParserBase
|
2019-05-18 21:07:23 +00:00
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "substitution"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2019-05-18 21:07:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** The expression element is one of: an expression in parentheses, an array, a literal, a function, an identifier, an asterisk.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserExpressionElement : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "element of expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** An expression element, possibly with an alias, if appropriate.
|
2011-11-06 04:21:09 +00:00
|
|
|
*/
|
2018-06-07 20:25:38 +00:00
|
|
|
class ParserWithOptionalAlias : public IParserBase
|
2011-11-06 04:21:09 +00:00
|
|
|
{
|
2011-11-06 20:47:07 +00:00
|
|
|
public:
|
2019-07-22 19:21:07 +00:00
|
|
|
ParserWithOptionalAlias(ParserPtr && elem_parser_, bool allow_alias_without_as_keyword_)
|
2019-10-31 15:22:48 +00:00
|
|
|
: elem_parser(std::move(elem_parser_)), allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
|
2011-11-06 04:21:09 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserPtr elem_parser;
|
|
|
|
bool allow_alias_without_as_keyword;
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "element of expression with optional alias"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2011-11-06 04:21:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-03-12 12:56:59 +00:00
|
|
|
/** Element of ORDER BY expression - same as expression element, but in addition, ASC[ENDING] | DESC[ENDING] could be specified
|
|
|
|
* and optionally, NULLS LAST|FIRST
|
|
|
|
* and optionally, COLLATE 'locale'.
|
2019-04-21 03:36:59 +00:00
|
|
|
* and optionally, WITH FILL [FROM x] [TO y] [STEP z]
|
2011-09-04 05:14:52 +00:00
|
|
|
*/
|
|
|
|
class ParserOrderByElement : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "element of ORDER BY expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2011-09-04 05:14:52 +00:00
|
|
|
};
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2019-10-07 16:23:16 +00:00
|
|
|
/** Parser for function with arguments like KEY VALUE (space separated)
|
2019-10-08 13:26:15 +00:00
|
|
|
* no commas alowed, just space-separated pairs.
|
2019-10-07 16:23:16 +00:00
|
|
|
*/
|
|
|
|
class ParserFunctionWithKeyValueArguments : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "function with key-value arguments"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Data type or table engine, possibly with parameters. For example, UInt8 or see examples from ParserIdentifierWithParameters
|
|
|
|
* Parse result is ASTFunction, with or without arguments.
|
|
|
|
*/
|
|
|
|
class ParserIdentifierWithOptionalParameters : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override{ return "identifier with optional parameters"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2019-10-07 16:23:16 +00:00
|
|
|
};
|
|
|
|
|
2019-10-09 13:02:05 +00:00
|
|
|
/** Element of TTL expression - same as expression element, but in addition,
|
|
|
|
* TO DISK 'xxx' | TO VOLUME 'xxx' | DELETE could be specified
|
|
|
|
*/
|
|
|
|
class ParserTTLElement : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "element of TTL expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2019-10-09 13:02:05 +00:00
|
|
|
};
|
|
|
|
|
2011-09-04 05:14:52 +00:00
|
|
|
}
|