Merge pull request #35727 from kssenii/fix-any-all

Fix any/all(subquery)
This commit is contained in:
Kseniia Sumarokova 2022-03-31 10:05:37 +02:00 committed by GitHub
commit 0b20329156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 10 deletions

View File

@ -328,14 +328,20 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, ASTPtr & node
ASTPtr elem; ASTPtr elem;
SubqueryFunctionType subquery_function_type = SubqueryFunctionType::NONE; SubqueryFunctionType subquery_function_type = SubqueryFunctionType::NONE;
if (allow_any_all_operators && ParserKeyword("ANY").ignore(pos, expected))
subquery_function_type = SubqueryFunctionType::ANY; if (comparison_expression)
else if (allow_any_all_operators && ParserKeyword("ALL").ignore(pos, expected)) {
subquery_function_type = SubqueryFunctionType::ALL; if (ParserKeyword("ANY").ignore(pos, expected))
else if (!(remaining_elem_parser ? remaining_elem_parser : first_elem_parser)->parse(pos, elem, expected)) subquery_function_type = SubqueryFunctionType::ANY;
return false; else if (ParserKeyword("ALL").ignore(pos, expected))
subquery_function_type = SubqueryFunctionType::ALL;
}
if (subquery_function_type != SubqueryFunctionType::NONE && !ParserSubquery().parse(pos, elem, expected)) if (subquery_function_type != SubqueryFunctionType::NONE && !ParserSubquery().parse(pos, elem, expected))
subquery_function_type = SubqueryFunctionType::NONE;
if (subquery_function_type == SubqueryFunctionType::NONE
&& !(remaining_elem_parser ? remaining_elem_parser : first_elem_parser)->parse(pos, elem, expected))
return false; return false;
/// the first argument of the function is the previous element, the second is the next one /// the first argument of the function is the previous element, the second is the next one
@ -346,7 +352,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, ASTPtr & node
exp_list->children.push_back(node); exp_list->children.push_back(node);
exp_list->children.push_back(elem); exp_list->children.push_back(elem);
if (allow_any_all_operators && subquery_function_type != SubqueryFunctionType::NONE && !modifyAST(function, subquery_function_type)) if (comparison_expression && subquery_function_type != SubqueryFunctionType::NONE && !modifyAST(function, subquery_function_type))
return false; return false;
/** special exception for the access operator to the element of the array `x[y]`, which /** special exception for the access operator to the element of the array `x[y]`, which

View File

@ -122,7 +122,7 @@ private:
ParserPtr first_elem_parser; ParserPtr first_elem_parser;
ParserPtr remaining_elem_parser; ParserPtr remaining_elem_parser;
/// =, !=, <, > ALL (subquery) / ANY (subquery) /// =, !=, <, > ALL (subquery) / ANY (subquery)
bool allow_any_all_operators = false; bool comparison_expression = false;
public: public:
/** `operators_` - allowed operators and their corresponding functions /** `operators_` - allowed operators and their corresponding functions
@ -133,9 +133,9 @@ public:
} }
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserLeftAssociativeBinaryOperatorList(Operators_t operators_,
Operators_t overlapping_operators_to_skip_, ParserPtr && first_elem_parser_, bool allow_any_all_operators_ = false) Operators_t overlapping_operators_to_skip_, ParserPtr && first_elem_parser_, bool comparison_expression_ = false)
: operators(operators_), overlapping_operators_to_skip(overlapping_operators_to_skip_), : 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_) first_elem_parser(std::move(first_elem_parser_)), comparison_expression(comparison_expression_)
{ {
} }

View File

@ -49,3 +49,7 @@ select 11 > all (select 11 from numbers(10));
0 0
select 11 >= all (select 11 from numbers(10)); select 11 >= all (select 11 from numbers(10));
1 1
select sum(number) = any(number) from numbers(1) group by number;
1
select 1 == any (1);
1

View File

@ -24,3 +24,5 @@ select 11 <= all (select number from numbers(11));
select 11 < all (select 11 from numbers(10)); select 11 < all (select 11 from numbers(10));
select 11 > all (select 11 from numbers(10)); select 11 > all (select 11 from numbers(10));
select 11 >= all (select 11 from numbers(10)); select 11 >= all (select 11 from numbers(10));
select sum(number) = any(number) from numbers(1) group by number;
select 1 == any (1);