From e1b6acfa5284112d365fd48b65eb43391f005eca Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 21 Oct 2021 21:18:00 +0300 Subject: [PATCH] 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 --- src/Parsers/ASTFunction.cpp | 4 ++++ .../0_stateless/02035_isNull_isNotNull_format.reference | 5 +++++ tests/queries/0_stateless/02035_isNull_isNotNull_format.sql | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/Parsers/ASTFunction.cpp b/src/Parsers/ASTFunction.cpp index 3c78c4060d6..4423f47b830 100644 --- a/src/Parsers/ASTFunction.cpp +++ b/src/Parsers/ASTFunction.cpp @@ -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; diff --git a/tests/queries/0_stateless/02035_isNull_isNotNull_format.reference b/tests/queries/0_stateless/02035_isNull_isNotNull_format.reference index 74fc4a44b5f..4964bc68fff 100644 --- a/tests/queries/0_stateless/02035_isNull_isNotNull_format.reference +++ b/tests/queries/0_stateless/02035_isNull_isNotNull_format.reference @@ -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 diff --git a/tests/queries/0_stateless/02035_isNull_isNotNull_format.sql b/tests/queries/0_stateless/02035_isNull_isNotNull_format.sql index eff658445a8..d9138e12bca 100644 --- a/tests/queries/0_stateless/02035_isNull_isNotNull_format.sql +++ b/tests/queries/0_stateless/02035_isNull_isNotNull_format.sql @@ -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);