From 45ad297a1dd6c610dc3266f1b529727ca3ebbbe8 Mon Sep 17 00:00:00 2001 From: Pxl Date: Sun, 26 Mar 2023 11:41:34 +0800 Subject: [PATCH] [Enchancement](function) change aggregate function creator to return AggregateFunctionPtr (#18025) change creator_type to return AggregateFunctionPtr. remove some function and use creator directly. --- ...gregate_function_approx_count_distinct.cpp | 17 ++--- .../aggregate_function_avg.cpp | 19 +---- .../aggregate_function_avg_weighted.cpp | 12 +-- .../aggregate_function_bit.cpp | 26 ++----- .../aggregate_function_bitmap.cpp | 42 ++++------- .../aggregate_function_collect.cpp | 14 ++-- .../aggregate_function_distinct.cpp | 24 +++--- .../aggregate_function_group_concat.cpp | 14 ++-- .../aggregate_function_histogram.cpp | 14 ++-- .../aggregate_function_hll_union_agg.cpp | 21 ++---- .../aggregate_function_min_max.cpp | 73 +++++++------------ .../aggregate_function_min_max.h | 16 +--- .../aggregate_function_min_max_by.cpp | 48 +++++------- .../aggregate_function_orthogonal_bitmap.cpp | 70 ++++-------------- .../aggregate_function_percentile_approx.cpp | 39 +++------- .../aggregate_function_reader.cpp | 13 ++-- .../aggregate_function_retention.cpp | 12 +-- .../aggregate_function_sequence_match.cpp | 22 +++--- .../aggregate_function_stddev.cpp | 59 +++++++-------- .../aggregate_function_sum.cpp | 50 +------------ .../aggregate_function_sum.h | 17 ++++- .../aggregate_function_topn.cpp | 52 ++++++------- .../aggregate_function_uniq.cpp | 27 +++---- .../aggregate_function_window.cpp | 37 +--------- .../aggregate_function_window_funnel.cpp | 12 ++- be/src/vec/aggregate_functions/helpers.h | 56 +++++++++++--- .../array/function_array_aggregation.cpp | 11 ++- 27 files changed, 286 insertions(+), 531 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp b/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp index 2c22586d43..3083b9c7b1 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_approx_count_distinct.cpp @@ -18,28 +18,21 @@ #include "vec/aggregate_functions/aggregate_function_approx_count_distinct.h" #include "vec/aggregate_functions/helpers.h" -#include "vec/utils/template_helpers.hpp" namespace doris::vectorized { AggregateFunctionPtr create_aggregate_function_approx_count_distinct( const std::string& name, const DataTypes& argument_types, const bool result_is_nullable) { - AggregateFunctionPtr res = nullptr; WhichDataType which(remove_nullable(argument_types[0])); -#define DISPATCH(TYPE, COLUMN_TYPE) \ - if (which.idx == TypeIndex::TYPE) \ - res.reset(creator_without_type::create>( \ - result_is_nullable, argument_types)); +#define DISPATCH(TYPE, COLUMN_TYPE) \ + if (which.idx == TypeIndex::TYPE) \ + return creator_without_type::create>( \ + argument_types, result_is_nullable); TYPE_TO_COLUMN_TYPE(DISPATCH) #undef DISPATCH - if (!res) { - LOG(WARNING) << fmt::format("Illegal type {} of argument for aggregate function {}", - argument_types[0]->get_name(), name); - } - - return res; + return nullptr; } void register_aggregate_function_approx_count_distinct(AggregateFunctionSimpleFactory& factory) { diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg.cpp b/be/src/vec/aggregate_functions/aggregate_function_avg.cpp index 4f493c9529..f6fe08a9e3 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_avg.cpp @@ -20,9 +20,7 @@ #include "vec/aggregate_functions/aggregate_function_avg.h" -#include "common/logging.h" #include "vec/aggregate_functions/aggregate_function_simple_factory.h" -#include "vec/aggregate_functions/factory_helpers.h" #include "vec/aggregate_functions/helpers.h" namespace doris::vectorized { @@ -36,22 +34,7 @@ struct Avg { template using AggregateFuncAvg = typename Avg::Function; -AggregateFunctionPtr create_aggregate_function_avg(const std::string& name, - const DataTypes& argument_types, - const bool result_is_nullable) { - assert_unary(name, argument_types); - - AggregateFunctionPtr res( - creator_with_type::create(result_is_nullable, argument_types)); - - if (!res) { - LOG(WARNING) << fmt::format("Illegal type {} of argument for aggregate function {}", - argument_types[0]->get_name(), name); - } - return res; -} - void register_aggregate_function_avg(AggregateFunctionSimpleFactory& factory) { - factory.register_function_both("avg", create_aggregate_function_avg); + factory.register_function_both("avg", creator_with_type::creator); } } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg_weighted.cpp b/be/src/vec/aggregate_functions/aggregate_function_avg_weighted.cpp index c81bf4b42f..fc5df5303f 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg_weighted.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_avg_weighted.cpp @@ -19,18 +19,10 @@ #include "vec/aggregate_functions/aggregate_function_simple_factory.h" #include "vec/aggregate_functions/helpers.h" -#include "vec/data_types/data_type_nullable.h" namespace doris::vectorized { - -AggregateFunctionPtr create_aggregate_function_avg_weight(const std::string& name, - const DataTypes& argument_types, - const bool result_is_nullable) { - return AggregateFunctionPtr(creator_with_type::create( - result_is_nullable, argument_types)); -} - void register_aggregate_function_avg_weighted(AggregateFunctionSimpleFactory& factory) { - factory.register_function_both("avg_weighted", create_aggregate_function_avg_weight); + factory.register_function_both("avg_weighted", + creator_with_type::creator); } } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_bit.cpp b/be/src/vec/aggregate_functions/aggregate_function_bit.cpp index bdc51daaf9..97a6c0e92f 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_bit.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_bit.cpp @@ -25,28 +25,16 @@ namespace doris::vectorized { -template