Skip to content

Commit

Permalink
[refactor](agg) use unique_ptr in agg function (apache#44858)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterylh authored Dec 3, 2024
1 parent 702ca90 commit 3faf567
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions be/src/vec/aggregate_functions/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ struct creator_without_type {
template <typename AggregateFunctionTemplate, typename... TArgs>
static AggregateFunctionPtr create(const DataTypes& argument_types_,
const bool result_is_nullable, TArgs&&... args) {
IAggregateFunction* result(new AggregateFunctionTemplate(std::forward<TArgs>(args)...,
remove_nullable(argument_types_)));
std::unique_ptr<IAggregateFunction> result(std::make_unique<AggregateFunctionTemplate>(
std::forward<TArgs>(args)..., remove_nullable(argument_types_)));
if (have_nullable(argument_types_)) {
std::visit(
[&](auto multi_arguments, auto result_is_nullable) {
result = new NullableT<multi_arguments, result_is_nullable,
AggregateFunctionTemplate>(result, argument_types_);
result.reset(new NullableT<multi_arguments, result_is_nullable,
AggregateFunctionTemplate>(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
Expand All @@ -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<TArgs>(args)..., argument_types_));
std::unique_ptr<IAggregateFunction> result = std::make_unique<AggregateFunctionTemplate>(
std::forward<TArgs>(args)..., argument_types_);
CHECK_AGG_FUNCTION_SERIALIZED_TYPE(AggregateFunctionTemplate);
return AggregateFunctionPtr(result);
return AggregateFunctionPtr(result.release());
}
};

Expand Down

0 comments on commit 3faf567

Please sign in to comment.