diff --git a/src/AggregateFunctions/AggregateFunctionNothing.cpp b/src/AggregateFunctions/AggregateFunctionNothing.cpp index f1ac04e9890..ebeffffc71e 100644 --- a/src/AggregateFunctions/AggregateFunctionNothing.cpp +++ b/src/AggregateFunctions/AggregateFunctionNothing.cpp @@ -14,7 +14,8 @@ void registerAggregateFunctionNothing(AggregateFunctionFactory & factory) { assertNoParameters(name, parameters); - return std::make_shared(argument_types, parameters); + auto result_type = argument_types.empty() ? std::make_shared(std::make_shared()) : argument_types.front(); + return std::make_shared(argument_types, parameters, result_type); }); } diff --git a/src/AggregateFunctions/AggregateFunctionNothing.h b/src/AggregateFunctions/AggregateFunctionNothing.h index 3c530e71dc9..8c1b95c26b0 100644 --- a/src/AggregateFunctions/AggregateFunctionNothing.h +++ b/src/AggregateFunctions/AggregateFunctionNothing.h @@ -24,13 +24,8 @@ namespace ErrorCodes class AggregateFunctionNothing final : public IAggregateFunctionHelper { public: - AggregateFunctionNothing(const DataTypes & arguments, const Array & params) - : IAggregateFunctionHelper( - arguments, - params, - arguments.empty() ? std::make_shared(std::make_shared()) : arguments.front()) - { - } + AggregateFunctionNothing(const DataTypes & arguments, const Array & params, const DataTypePtr & result_type_) + : IAggregateFunctionHelper(arguments, params, result_type_) {} String getName() const override { diff --git a/src/AggregateFunctions/Combinators/AggregateFunctionNull.cpp b/src/AggregateFunctions/Combinators/AggregateFunctionNull.cpp index 5e47af54d6c..1f5bf4c3818 100644 --- a/src/AggregateFunctions/Combinators/AggregateFunctionNull.cpp +++ b/src/AggregateFunctions/Combinators/AggregateFunctionNull.cpp @@ -101,14 +101,10 @@ public: if (has_null_types) { /// Currently the only functions that returns not-NULL on all NULL arguments are count and uniq, and they returns UInt64. - /// In that case we need to set type of first argument to UInt64 to have in as a result type. if (properties.returns_default_when_only_null) - { - DataTypes new_arguments = {std::make_shared()}; - std::copy(arguments.begin(), arguments.end(), std::back_inserter(new_arguments)); - return std::make_shared(new_arguments, params); - } - return std::make_shared(arguments, params); + return std::make_shared(arguments, params, std::make_shared()); + else + return std::make_shared(arguments, params, std::make_shared(std::make_shared())); } assert(nested_function); diff --git a/src/Analyzer/Passes/QueryAnalysisPass.cpp b/src/Analyzer/Passes/QueryAnalysisPass.cpp index 0b161693357..6caef751ae7 100644 --- a/src/Analyzer/Passes/QueryAnalysisPass.cpp +++ b/src/Analyzer/Passes/QueryAnalysisPass.cpp @@ -5194,11 +5194,11 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi * Also we don't want to replace first argument, but just prepend it because it may have aliases, for example * SELECT count(NULL AS a), sum(a) FROM table */ - const auto & actual_argument_types = aggregate_function->getArgumentTypes(); - if (!actual_argument_types.empty() && !argument_types.empty() && !argument_types[0]->equals(*actual_argument_types[0])) + const auto & actual_result_type = aggregate_function->getResultType(); + if (!argument_types.empty() && !argument_types.front()->equals(*actual_result_type)) { QueryTreeNodes & nodes = function_node.getArguments().getNodes(); - QueryTreeNodes new_nodes = {std::make_shared(actual_argument_types[0]->getDefault(), actual_argument_types[0])}; + QueryTreeNodes new_nodes = {std::make_shared(actual_result_type->getDefault(), actual_result_type)}; std::move(nodes.begin(), nodes.end(), std::back_inserter(new_nodes)); nodes = std::move(new_nodes); }