Add missing parenthesis for isNotNull/isNull rewrites to IS [NOT] NULL

After #29446 the following query was "broken":

    select isNotNull(1)+isNotNull(2) from remote('127.2', system.one)

This was also a problem for queries to external storages (i.e. mysql),
since it also uses query rewrite, like non-local distributed queries.

Fixes: #29446
This commit is contained in:
Azat Khuzhin 2021-10-21 21:18:00 +03:00
parent fa1b587635
commit e1b6acfa52
3 changed files with 11 additions and 0 deletions

View File

@ -294,8 +294,12 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
continue;
}
if (frame.need_parens)
settings.ostr << '(';
arguments->formatImpl(settings, state, nested_need_parens);
settings.ostr << (settings.hilite ? hilite_operator : "") << func[1] << (settings.hilite ? hilite_none : "");
if (frame.need_parens)
settings.ostr << ')';
written = true;

View File

@ -7,3 +7,8 @@ explain syntax select isNull(null);
SELECT NULL IS NULL
explain syntax select isNotNull(null);
SELECT NULL IS NOT NULL
explain syntax select isNotNull(1)+isNotNull(2) from remote('127.2', system.one);
SELECT (1 IS NOT NULL) + (2 IS NOT NULL)
FROM remote(\'127.2\', \'system.one\')
select isNotNull(1)+isNotNull(2) from remote('127.2', system.one);
2

View File

@ -3,3 +3,5 @@ explain syntax select null is null;
explain syntax select null is not null;
explain syntax select isNull(null);
explain syntax select isNotNull(null);
explain syntax select isNotNull(1)+isNotNull(2) from remote('127.2', system.one);
select isNotNull(1)+isNotNull(2) from remote('127.2', system.one);