2011-09-04 05:14:52 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2010-06-25 16:36:13 +00:00
|
|
|
#include <list>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IParserBase.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2021-05-04 03:43:17 +00:00
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
2021-11-26 18:27:16 +00:00
|
|
|
#include <Parsers/SelectUnionMode.h>
|
2020-10-14 15:02:51 +00:00
|
|
|
#include <Common/IntervalKind.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** Consequent pairs of rows: the operator and the corresponding function. For example, "+" -> "plus".
|
|
|
|
* The parsing order of the operators is significant.
|
2010-06-25 16:36:13 +00:00
|
|
|
*/
|
2016-05-28 10:35:44 +00:00
|
|
|
using Operators_t = const char **;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** List of elements separated by something. */
|
2011-08-18 18:48:00 +00:00
|
|
|
class ParserList : public IParserBase
|
|
|
|
{
|
|
|
|
public:
|
2019-10-07 16:23:16 +00:00
|
|
|
ParserList(ParserPtr && elem_parser_, ParserPtr && separator_parser_, bool allow_empty_ = true, char result_separator_ = ',')
|
|
|
|
: elem_parser(std::move(elem_parser_))
|
|
|
|
, separator_parser(std::move(separator_parser_))
|
|
|
|
, allow_empty(allow_empty_)
|
|
|
|
, result_separator(result_separator_)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
}
|
2020-06-05 21:31:37 +00:00
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
static bool parseUtil(Pos & pos, Expected & expected, const F & parse_element, IParser & separator_parser_, bool allow_empty_ = true)
|
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
if (!parse_element())
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return allow_empty_;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
begin = pos;
|
|
|
|
if (!separator_parser_.ignore(pos, expected) || !parse_element())
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
static bool parseUtil(Pos & pos, Expected & expected, const F & parse_element, TokenType separator, bool allow_empty_ = true)
|
|
|
|
{
|
|
|
|
ParserToken sep_parser{separator};
|
|
|
|
return parseUtil(pos, expected, parse_element, sep_parser, allow_empty_);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
static bool parseUtil(Pos & pos, Expected & expected, const F & parse_element, bool allow_empty_ = true)
|
|
|
|
{
|
|
|
|
return parseUtil(pos, expected, parse_element, TokenType::Comma, allow_empty_);
|
|
|
|
}
|
|
|
|
|
2011-08-18 18:48:00 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "list of elements"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2011-08-18 18:48:00 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserPtr elem_parser;
|
|
|
|
ParserPtr separator_parser;
|
|
|
|
bool allow_empty;
|
2019-10-07 16:23:16 +00:00
|
|
|
char result_separator;
|
2011-08-18 18:48:00 +00:00
|
|
|
};
|
|
|
|
|
2020-10-26 09:33:34 +00:00
|
|
|
class ParserUnionList : public IParserBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template <typename ElemFunc, typename SepFunc>
|
|
|
|
static bool parseUtil(Pos & pos, const ElemFunc & parse_element, const SepFunc & parse_separator)
|
|
|
|
{
|
|
|
|
Pos begin = pos;
|
|
|
|
if (!parse_element())
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
begin = pos;
|
|
|
|
if (!parse_separator() || !parse_element())
|
|
|
|
{
|
|
|
|
pos = begin;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto getUnionModes() const { return union_modes; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "list of union elements"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
private:
|
2021-11-26 18:27:16 +00:00
|
|
|
SelectUnionModes union_modes;
|
2020-10-26 09:33:34 +00:00
|
|
|
};
|
2011-08-18 18:48:00 +00:00
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** An expression with an infix binary left-associative operator.
|
|
|
|
* For example, a + b - c + d.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserLeftAssociativeBinaryOperatorList : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Operators_t operators;
|
2020-11-10 10:23:46 +00:00
|
|
|
Operators_t overlapping_operators_to_skip = { (const char *[]){ nullptr } };
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserPtr first_elem_parser;
|
|
|
|
ParserPtr remaining_elem_parser;
|
2021-08-15 06:55:43 +00:00
|
|
|
/// =, !=, <, > ALL (subquery) / ANY (subquery)
|
|
|
|
bool allow_any_all_operators = false;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-27 17:29:55 +00:00
|
|
|
/** `operators_` - allowed operators and their corresponding functions
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserPtr && first_elem_parser_)
|
|
|
|
: operators(operators_), first_elem_parser(std::move(first_elem_parser_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-15 06:55:43 +00:00
|
|
|
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_,
|
|
|
|
Operators_t overlapping_operators_to_skip_, ParserPtr && first_elem_parser_, bool allow_any_all_operators_ = false)
|
|
|
|
: operators(operators_), overlapping_operators_to_skip(overlapping_operators_to_skip_),
|
|
|
|
first_elem_parser(std::move(first_elem_parser_)), allow_any_all_operators(allow_any_all_operators_)
|
2020-11-10 10:23:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserPtr && first_elem_parser_,
|
|
|
|
ParserPtr && remaining_elem_parser_)
|
|
|
|
: operators(operators_), first_elem_parser(std::move(first_elem_parser_)),
|
|
|
|
remaining_elem_parser(std::move(remaining_elem_parser_))
|
|
|
|
{
|
|
|
|
}
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "list, delimited by binary operators"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
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
|
|
|
/** Expression with an infix operator of arbitrary arity.
|
|
|
|
* For example, a AND b AND c AND d.
|
2014-02-13 11:05:51 +00:00
|
|
|
*/
|
|
|
|
class ParserVariableArityOperatorList : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-07-10 03:28:12 +00:00
|
|
|
const char * infix;
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * function_name;
|
|
|
|
ParserPtr elem_parser;
|
2014-02-13 11:05:51 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserVariableArityOperatorList(const char * infix_, const char * function_, ParserPtr && elem_parser_)
|
2017-07-10 03:28:12 +00:00
|
|
|
: infix(infix_), function_name(function_), elem_parser(std::move(elem_parser_))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
}
|
2014-02-13 11:05:51 +00:00
|
|
|
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "list, delimited by operator of variable arity"; }
|
2014-02-13 11:05:51 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2014-02-13 11:05:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** An expression with a prefix unary operator.
|
|
|
|
* Example, NOT x.
|
2010-06-24 19:12:10 +00:00
|
|
|
*/
|
|
|
|
class ParserPrefixUnaryOperatorExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Operators_t operators;
|
|
|
|
ParserPtr elem_parser;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-27 17:29:55 +00:00
|
|
|
/** `operators_` - allowed operators and their corresponding functions
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
ParserPrefixUnaryOperatorExpression(Operators_t operators_, ParserPtr && elem_parser_)
|
|
|
|
: operators(operators_), elem_parser(std::move(elem_parser_))
|
|
|
|
{
|
|
|
|
}
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "expression with prefix unary operator"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2021-05-04 03:43:17 +00:00
|
|
|
/// CAST operator "::". This parser is used if left argument
|
|
|
|
/// of operator cannot be read as simple literal from text of query.
|
|
|
|
/// Example: "[1, 1 + 1, 1 + 2]::Array(UInt8)"
|
|
|
|
class ParserCastExpression : public IParserBase
|
|
|
|
{
|
2022-02-01 15:56:03 +00:00
|
|
|
private:
|
|
|
|
ParserPtr elem_parser;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ParserCastExpression(ParserPtr && elem_parser_)
|
|
|
|
: elem_parser(std::move(elem_parser_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-04 03:43:17 +00:00
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "CAST expression"; }
|
|
|
|
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2019-10-31 15:22:48 +00:00
|
|
|
class ParserArrayElementExpression : public IParserBase
|
2010-06-24 19:12:10 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2015-01-16 10:17:58 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override{ return "array element expression"; }
|
2015-11-07 23:18:39 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2015-11-07 23:18:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-10-31 15:22:48 +00:00
|
|
|
class ParserTupleElementExpression : public IParserBase
|
2015-11-07 23:18:39 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2015-11-07 23:18:39 +00:00
|
|
|
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "tuple element expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-20 19:34:18 +00:00
|
|
|
class ParserUnaryExpression : public IParserBase
|
2010-06-24 19:12:10 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2022-02-01 15:56:03 +00:00
|
|
|
ParserPrefixUnaryOperatorExpression operator_parser {operators, std::make_unique<ParserCastExpression>(std::make_unique<ParserTupleElementExpression>())};
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2021-06-20 19:34:18 +00:00
|
|
|
const char * getName() const override { return "unary expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ParserMultiplicativeExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2021-06-20 19:34:18 +00:00
|
|
|
ParserLeftAssociativeBinaryOperatorList operator_parser {operators, std::make_unique<ParserUnaryExpression>()};
|
2014-03-10 14:47:04 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-03-17 21:56:47 +00:00
|
|
|
const char * getName() const override { return "multiplicative expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
2020-03-17 21:56:47 +00:00
|
|
|
/// DATE operator. "DATE '2001-01-01'" would be parsed as "toDate('2001-01-01')".
|
|
|
|
class ParserDateOperatorExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ParserMultiplicativeExpression next_parser;
|
|
|
|
|
|
|
|
const char * getName() const override { return "DATE operator expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// TIMESTAMP operator. "TIMESTAMP '2001-01-01 12:34:56'" would be parsed as "toDateTime('2001-01-01 12:34:56')".
|
|
|
|
class ParserTimestampOperatorExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ParserDateOperatorExpression next_parser;
|
|
|
|
|
|
|
|
const char * getName() const override { return "TIMESTAMP operator expression"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-10-30 02:18:06 +00:00
|
|
|
/// Optional conversion to INTERVAL data type. Example: "INTERVAL x SECOND" parsed as "toIntervalSecond(x)".
|
|
|
|
class ParserIntervalOperatorExpression : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-03-17 21:56:47 +00:00
|
|
|
ParserTimestampOperatorExpression next_parser;
|
2017-10-30 02:18:06 +00:00
|
|
|
|
2020-03-17 21:56:47 +00:00
|
|
|
const char * getName() const override { return "INTERVAL operator expression"; }
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2020-10-15 10:48:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool parseArgumentAndIntervalKind(Pos & pos, ASTPtr & expr, IntervalKind & interval_kind, Expected & expected);
|
2017-10-30 02:18:06 +00:00
|
|
|
};
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
class ParserAdditiveExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2017-10-30 02:18:06 +00:00
|
|
|
ParserLeftAssociativeBinaryOperatorList operator_parser {operators, std::make_unique<ParserIntervalOperatorExpression>()};
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-03-17 21:56:47 +00:00
|
|
|
const char * getName() const override { return "additive expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-20 04:47:51 +00:00
|
|
|
class ParserConcatExpression : public IParserBase
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserVariableArityOperatorList operator_parser {"||", "concat", std::make_unique<ParserAdditiveExpression>()};
|
2016-11-20 04:47:51 +00:00
|
|
|
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "string concatenation expression"; }
|
2016-11-20 04:47:51 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-11-20 04:47:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-03 01:15:53 +00:00
|
|
|
class ParserBetweenExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserConcatExpression elem_parser;
|
2016-04-03 01:15:53 +00:00
|
|
|
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "BETWEEN expression"; }
|
2016-04-03 01:15:53 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2016-04-03 01:15:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
class ParserComparisonExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
2020-11-10 10:23:46 +00:00
|
|
|
static const char * overlapping_operators_to_skip[];
|
2021-08-15 06:55:43 +00:00
|
|
|
ParserLeftAssociativeBinaryOperatorList operator_parser {operators,
|
|
|
|
overlapping_operators_to_skip, std::make_unique<ParserBetweenExpression>(), true};
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override{ return "comparison expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2021-08-15 06:55:43 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
|
|
|
{
|
|
|
|
return operator_parser.parse(pos, node, expected);
|
|
|
|
}
|
2021-05-30 17:58:08 +00:00
|
|
|
};
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2016-07-18 16:12:29 +00:00
|
|
|
/** Parser for nullity checking with IS (NOT) NULL.
|
|
|
|
*/
|
|
|
|
class ParserNullityChecking : public IParserBase
|
|
|
|
{
|
2019-10-31 15:22:48 +00:00
|
|
|
private:
|
2021-06-03 02:19:07 +00:00
|
|
|
ParserComparisonExpression elem_parser;
|
2021-08-15 06:55:43 +00:00
|
|
|
|
2016-07-18 16:12:29 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * getName() const override { return "nullity checking"; }
|
2017-07-10 03:28:12 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2016-07-18 16:12:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
class ParserLogicalNotExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
static const char * operators[];
|
|
|
|
ParserPrefixUnaryOperatorExpression operator_parser {operators, std::make_unique<ParserNullityChecking>()};
|
2014-03-10 14:47:04 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override{ return "logical-NOT expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ParserLogicalAndExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserVariableArityOperatorList operator_parser {"AND", "and", std::make_unique<ParserLogicalNotExpression>()};
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "logical-AND expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ParserLogicalOrExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserVariableArityOperatorList operator_parser {"OR", "or", std::make_unique<ParserLogicalAndExpression>()};
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "logical-OR expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return operator_parser.parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-30 17:31:05 +00:00
|
|
|
/** An expression with ternary operator.
|
|
|
|
* For example, a = 1 ? b + 1 : c * 2.
|
2012-09-23 06:16:42 +00:00
|
|
|
*/
|
|
|
|
class ParserTernaryOperatorExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserLogicalOrExpression elem_parser;
|
2012-09-23 06:16:42 +00:00
|
|
|
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "expression with ternary operator"; }
|
2012-09-23 06:16:42 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2012-09-23 06:16:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-08 09:52:02 +00:00
|
|
|
class ParserLambdaExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserTernaryOperatorExpression elem_parser;
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2013-05-08 09:52:02 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "lambda expression"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2013-05-08 09:52:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-13 05:18:14 +00:00
|
|
|
// It's used to parse expressions in table function.
|
|
|
|
class ParserTableFunctionExpression : public IParserBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ParserLambdaExpression elem_parser;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "table function expression"; }
|
|
|
|
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-07-12 02:40:28 +00:00
|
|
|
using ParserExpression = ParserLambdaExpression;
|
|
|
|
|
|
|
|
|
2011-11-06 20:47:07 +00:00
|
|
|
class ParserExpressionWithOptionalAlias : public IParserBase
|
|
|
|
{
|
|
|
|
public:
|
2021-02-13 05:18:14 +00:00
|
|
|
explicit ParserExpressionWithOptionalAlias(bool allow_alias_without_as_keyword, bool is_table_function = false);
|
2011-11-06 20:47:07 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserPtr impl;
|
2011-11-06 20:47:07 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "expression with optional alias"; }
|
2015-04-11 03:10:23 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-10 03:28:12 +00:00
|
|
|
return impl->parse(pos, node, expected);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2011-11-06 20:47:07 +00:00
|
|
|
};
|
|
|
|
|
2017-10-30 02:18:06 +00:00
|
|
|
|
2017-05-27 17:29:55 +00:00
|
|
|
/** A comma-separated list of expressions, probably empty. */
|
2010-06-24 19:12:10 +00:00
|
|
|
class ParserExpressionList : public IParserBase
|
|
|
|
{
|
2015-11-08 00:28:12 +00:00
|
|
|
public:
|
2021-02-13 05:18:14 +00:00
|
|
|
explicit ParserExpressionList(bool allow_alias_without_as_keyword_, bool is_table_function_ = false)
|
|
|
|
: allow_alias_without_as_keyword(allow_alias_without_as_keyword_), is_table_function(is_table_function_) {}
|
2015-11-08 00:28:12 +00:00
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
bool allow_alias_without_as_keyword;
|
2021-02-13 05:18:14 +00:00
|
|
|
bool is_table_function; // This expression list is used by a table function
|
2015-11-08 00:28:12 +00:00
|
|
|
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "list of expressions"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ParserNotEmptyExpressionList : public IParserBase
|
|
|
|
{
|
2015-11-08 00:28:12 +00:00
|
|
|
public:
|
2021-02-13 05:18:14 +00:00
|
|
|
explicit ParserNotEmptyExpressionList(bool allow_alias_without_as_keyword)
|
2019-07-22 19:21:07 +00:00
|
|
|
: nested_parser(allow_alias_without_as_keyword) {}
|
2010-06-24 19:12:10 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ParserExpressionList nested_parser;
|
2010-06-24 19:12:10 +00:00
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "not empty list of expressions"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
2010-06-24 19:12:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-04 05:14:52 +00:00
|
|
|
class ParserOrderByExpressionList : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "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-08 13:26:15 +00:00
|
|
|
/// Parser for key-value pair, where value can be list of pairs.
|
2019-10-07 16:23:16 +00:00
|
|
|
class ParserKeyValuePair : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "key-value pair"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2019-10-09 13:02:05 +00:00
|
|
|
|
2019-10-08 13:26:15 +00:00
|
|
|
/// Parser for list of key-value pairs.
|
2019-10-07 16:23:16 +00:00
|
|
|
class ParserKeyValuePairsList : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "list of pairs"; }
|
|
|
|
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
|
|
|
};
|
|
|
|
|
2019-10-09 13:02:05 +00:00
|
|
|
|
|
|
|
class ParserTTLExpressionList : public IParserBase
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-21 08:54:26 +00:00
|
|
|
const char * getName() const override { return "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
|
|
|
}
|