diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 5df5d6f7a42..0a656383dc3 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -121,7 +121,7 @@ struct CustomizeAggregateFunctionsSuffixData void visit(ASTFunction & func, ASTPtr &) const { const auto & instance = AggregateFunctionFactory::instance(); - if (instance.isAggregateFunctionName(func.name)) + if (instance.isAggregateFunctionName(func.name) && !endsWith(func.name, "OrNull")) { auto properties = instance.tryGetProperties(func.name); if (properties && !properties->returns_default_when_only_null) @@ -165,10 +165,13 @@ struct CustomizeAggregateFunctionsMoveSuffixData const auto & instance = AggregateFunctionFactory::instance(); if (instance.isAggregateFunctionName(func.name)) { - auto properties = instance.tryGetProperties(func.name); - if (properties && !properties->returns_default_when_only_null) + if (endsWith(func.name, "OrNull")) { - func.name = moveSuffixAhead(func.name); + auto properties = instance.tryGetProperties(func.name); + if (properties && !properties->returns_default_when_only_null) + { + func.name = moveSuffixAhead(func.name); + } } } } diff --git a/tests/queries/0_stateless/01562_agg_null_for_empty_ahead.reference b/tests/queries/0_stateless/01562_agg_null_for_empty_ahead.reference index bda1162f4e9..a197ceee71f 100644 --- a/tests/queries/0_stateless/01562_agg_null_for_empty_ahead.reference +++ b/tests/queries/0_stateless/01562_agg_null_for_empty_ahead.reference @@ -2,7 +2,7 @@ 0 0 0 -\N +0 1 \N \N