Merge pull request #57713 from evillique/fix-unary-operators-parsing

Fix unary operators parsing
This commit is contained in:
Nikolay Degterinsky 2023-12-11 13:18:00 +01:00 committed by GitHub
commit 64cd83fcd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -468,7 +468,8 @@ enum class OperatorType
StartIf,
FinishIf,
Cast,
Lambda
Lambda,
Not
};
/** Operator struct stores parameters of the operator:
@ -2420,7 +2421,7 @@ const std::vector<std::pair<std::string_view, Operator>> ParserExpressionImpl::o
const std::vector<std::pair<std::string_view, Operator>> ParserExpressionImpl::unary_operators_table
{
{"NOT", Operator("not", 5, 1)},
{"NOT", Operator("not", 5, 1, OperatorType::Not)},
{"-", Operator("negate", 13, 1)},
{"", Operator("negate", 13, 1)}
};
@ -2592,7 +2593,16 @@ Action ParserExpressionImpl::tryParseOperand(Layers & layers, IParser::Pos & pos
if (cur_op != unary_operators_table.end())
{
layers.back()->pushOperator(cur_op->second);
if (cur_op->second.type == OperatorType::Not && pos->type == TokenType::OpeningRoundBracket)
{
++pos;
auto identifier = std::make_shared<ASTIdentifier>(cur_op->second.function_name);
layers.push_back(getFunctionLayer(identifier, layers.front()->is_table_function));
}
else
{
layers.back()->pushOperator(cur_op->second);
}
return Action::OPERAND;
}

View File

@ -0,0 +1 @@
SELECT NOT (0) + NOT (0);