From 3faf5672f5b40f4859fa66620194a3b81d1a6f79 Mon Sep 17 00:00:00 2001 From: peterylh Date: Tue, 3 Dec 2024 11:55:40 +0800 Subject: [PATCH] [refactor](agg) use unique_ptr in agg function (#44858) --- be/src/vec/aggregate_functions/helpers.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/be/src/vec/aggregate_functions/helpers.h b/be/src/vec/aggregate_functions/helpers.h index 75ef07bae646b8..ad21c2ca6c8d40 100644 --- a/be/src/vec/aggregate_functions/helpers.h +++ b/be/src/vec/aggregate_functions/helpers.h @@ -117,20 +117,21 @@ struct creator_without_type { template static AggregateFunctionPtr create(const DataTypes& argument_types_, const bool result_is_nullable, TArgs&&... args) { - IAggregateFunction* result(new AggregateFunctionTemplate(std::forward(args)..., - remove_nullable(argument_types_))); + std::unique_ptr result(std::make_unique( + std::forward(args)..., remove_nullable(argument_types_))); if (have_nullable(argument_types_)) { std::visit( [&](auto multi_arguments, auto result_is_nullable) { - result = new NullableT(result, argument_types_); + result.reset(new NullableT(result.release(), + argument_types_)); }, make_bool_variant(argument_types_.size() > 1), make_bool_variant(result_is_nullable)); } CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate); - return AggregateFunctionPtr(result); + return AggregateFunctionPtr(result.release()); } /// AggregateFunctionTemplate will handle the nullable arguments, no need to use @@ -139,10 +140,10 @@ struct creator_without_type { static AggregateFunctionPtr create_ignore_nullable(const DataTypes& argument_types_, const bool /*result_is_nullable*/, TArgs&&... args) { - IAggregateFunction* result( - new AggregateFunctionTemplate(std::forward(args)..., argument_types_)); + std::unique_ptr result = std::make_unique( + std::forward(args)..., argument_types_); CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate); - return AggregateFunctionPtr(result); + return AggregateFunctionPtr(result.release()); } };