mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Stable NOT chain formatting
This commit is contained in:
parent
4b1b612cfd
commit
c6339b4c08
@ -489,14 +489,12 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
|
||||
/** This is done, because among the unary operators there is only a minus and NOT.
|
||||
* But for a minus the chain of unary operators does not need to be supported.
|
||||
*/
|
||||
size_t count = 1;
|
||||
if (it[0] && 0 == strncmp(it[0], "NOT", 3))
|
||||
{
|
||||
/// Was there an even number of NOTs.
|
||||
bool even = false;
|
||||
|
||||
const char ** jt;
|
||||
while (true)
|
||||
{
|
||||
const char ** jt;
|
||||
for (jt = operators; *jt; jt += 2)
|
||||
if (parseOperator(pos, *jt, expected))
|
||||
break;
|
||||
@ -504,11 +502,8 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
|
||||
if (!*jt)
|
||||
break;
|
||||
|
||||
even = !even;
|
||||
++count;
|
||||
}
|
||||
|
||||
if (even)
|
||||
it = jt; /// Zero the result of parsing the first NOT. It turns out, as if there is no `NOT` chain at all.
|
||||
}
|
||||
|
||||
ASTPtr elem;
|
||||
@ -519,19 +514,25 @@ bool ParserPrefixUnaryOperatorExpression::parseImpl(Pos & pos, ASTPtr & node, Ex
|
||||
node = elem;
|
||||
else
|
||||
{
|
||||
/// the function corresponding to the operator
|
||||
auto function = std::make_shared<ASTFunction>();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
/// the function corresponding to the operator
|
||||
auto function = std::make_shared<ASTFunction>();
|
||||
|
||||
/// function arguments
|
||||
auto exp_list = std::make_shared<ASTExpressionList>();
|
||||
/// function arguments
|
||||
auto exp_list = std::make_shared<ASTExpressionList>();
|
||||
|
||||
function->name = it[1];
|
||||
function->arguments = exp_list;
|
||||
function->children.push_back(exp_list);
|
||||
function->name = it[1];
|
||||
function->arguments = exp_list;
|
||||
function->children.push_back(exp_list);
|
||||
|
||||
exp_list->children.push_back(elem);
|
||||
if (node)
|
||||
exp_list->children.push_back(node);
|
||||
else
|
||||
exp_list->children.push_back(elem);
|
||||
|
||||
node = function;
|
||||
node = function;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -0,0 +1,5 @@
|
||||
-- { echo }
|
||||
EXPLAIN SYNTAX SELECT NOT NOT (NOT (NOT (NULL)));
|
||||
SELECT NOT (NOT (NOT NOT NULL))
|
||||
EXPLAIN SYNTAX SELECT NOT (NOT (NOT NOT NULL));
|
||||
SELECT NOT (NOT (NOT NOT NULL))
|
3
tests/queries/0_stateless/01920_not_chain_format.sql
Normal file
3
tests/queries/0_stateless/01920_not_chain_format.sql
Normal file
@ -0,0 +1,3 @@
|
||||
-- { echo }
|
||||
EXPLAIN SYNTAX SELECT NOT NOT (NOT (NOT (NULL)));
|
||||
EXPLAIN SYNTAX SELECT NOT (NOT (NOT NOT NULL));
|
Loading…
Reference in New Issue
Block a user