diff --git a/be/src/exprs/topn_function.cpp b/be/src/exprs/topn_function.cpp index e956e5e627f06b..544f98086783ff 100644 --- a/be/src/exprs/topn_function.cpp +++ b/be/src/exprs/topn_function.cpp @@ -91,50 +91,10 @@ StringVal TopNFunctions::topn_finalize(FunctionContext* ctx, const StringVal& sr return result; } -template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const TinyIntVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const SmallIntVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const IntVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const BigIntVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const FloatVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DoubleVal&, const IntVal&, - StringVal*); template void TopNFunctions::topn_update(FunctionContext*, const StringVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, - StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const TinyIntVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const SmallIntVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const IntVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const BigIntVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const FloatVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DoubleVal&, const IntVal&, - const IntVal&, StringVal*); template void TopNFunctions::topn_update(FunctionContext*, const StringVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, - const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, - const IntVal&, StringVal*); } // namespace doris \ No newline at end of file diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt index 09e86e2f7d6704..b83013b1e11f41 100644 --- a/be/src/vec/CMakeLists.txt +++ b/be/src/vec/CMakeLists.txt @@ -32,6 +32,7 @@ set(VEC_FILES aggregate_functions/aggregate_function_reader.cpp aggregate_functions/aggregate_function_window.cpp aggregate_functions/aggregate_function_stddev.cpp + aggregate_functions/aggregate_function_topn.cpp aggregate_functions/aggregate_function_simple_factory.cpp columns/collator.cpp columns/column.cpp diff --git a/be/src/vec/aggregate_functions/aggregate_function.h b/be/src/vec/aggregate_functions/aggregate_function.h index 4c2ef36d7bb72c..c3b507245cbdfd 100644 --- a/be/src/vec/aggregate_functions/aggregate_function.h +++ b/be/src/vec/aggregate_functions/aggregate_function.h @@ -20,13 +20,6 @@ #pragma once -#include -#include -#include -#include -#include -#include - #include "vec/common/exception.h" #include "vec/core/block.h" #include "vec/core/column_numbers.h" @@ -95,13 +88,15 @@ class IAggregateFunction { Arena* arena) const = 0; /// Merges state (on which place points to) with other state of current aggregation function. - virtual void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena* arena) const = 0; + virtual void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena* arena) const = 0; /// Serializes state (to transmit it over the network, for example). virtual void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const = 0; /// Deserializes state. This function is called only for empty (just created) states. - virtual void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena* arena) const = 0; + virtual void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena* arena) const = 0; /// Returns true if a function requires Arena to handle own states (see add(), merge(), deserialize()). virtual bool allocates_memory_in_arena() const { return false; } @@ -114,21 +109,11 @@ class IAggregateFunction { */ virtual bool is_state() const { return false; } - /// if return false, during insert_result_into function, you colud get nullable result column, + /// if return false, during insert_result_into function, you colud get nullable result column, /// so could insert to null value by yourself, rather than by AggregateFunctionNullBase; /// because you maybe be calculate a invalid value, but want to use null replace it; virtual bool insert_to_null_default() const { return true; } - /** The inner loop that uses the function pointer is better than using the virtual function. - * The reason is that in the case of virtual functions GCC 5.1.2 generates code, - * which, at each iteration of the loop, reloads the function address (the offset value in the virtual function table) from memory to the register. - * This gives a performance drop on simple queries around 12%. - * After the appearance of better compilers, the code can be removed. - */ - using AddFunc = void (*)(const IAggregateFunction*, AggregateDataPtr, const IColumn**, size_t, - Arena*); - virtual AddFunc get_address_of_add_function() const = 0; - /** Contains a loop with calls to "add" function. You can collect arguments into array "places" * and do a single call to "add_batch" for devirtualization and inlining. */ @@ -150,12 +135,6 @@ class IAggregateFunction { AggregateDataPtr place, const IColumn** columns, Arena* arena) const = 0; - /** This is used for runtime code generation to determine, which header files to include in generated source. - * Always implement it as - * const char * get_header_file_path() const override { return __FILE__; } - */ - virtual const char* get_header_file_path() const = 0; - const DataTypes& get_argument_types() const { return argument_types; } const Array& get_parameters() const { return parameters; } @@ -167,18 +146,10 @@ class IAggregateFunction { /// Implement method to obtain an address of 'add' function. template class IAggregateFunctionHelper : public IAggregateFunction { -private: - static void add_free(const IAggregateFunction* that, AggregateDataPtr place, - const IColumn** columns, size_t row_num, Arena* arena) { - static_cast(*that).add(place, columns, row_num, arena); - } - public: IAggregateFunctionHelper(const DataTypes& argument_types_, const Array& parameters_) : IAggregateFunction(argument_types_, parameters_) {} - AddFunc get_address_of_add_function() const override { return &add_free; } - void add_batch(size_t batch_size, AggregateDataPtr* places, size_t place_offset, const IColumn** columns, Arena* arena) const override { for (size_t i = 0; i < batch_size; ++i) diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg.h b/be/src/vec/aggregate_functions/aggregate_function_avg.h index 18584ee91a3c21..7b40f9552a91b9 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_avg.h @@ -101,7 +101,8 @@ class AggregateFunctionAvg final this->data(place).count = 0; } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { this->data(place).sum += this->data(rhs).sum; this->data(place).count += this->data(rhs).count; } @@ -110,7 +111,8 @@ class AggregateFunctionAvg final this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } @@ -119,8 +121,6 @@ class AggregateFunctionAvg final column.get_data().push_back(this->data(place).template result()); } - const char* get_header_file_path() const override { return __FILE__; } - private: UInt32 scale; }; diff --git a/be/src/vec/aggregate_functions/aggregate_function_bitmap.h b/be/src/vec/aggregate_functions/aggregate_function_bitmap.h index a2e43e5392caf2..4d72f070bbf574 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_bitmap.h +++ b/be/src/vec/aggregate_functions/aggregate_function_bitmap.h @@ -16,8 +16,6 @@ // under the License. #pragma once -#include -#include #include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/column_complex.h" @@ -91,7 +89,8 @@ class AggregateFunctionBitmapOp final this->data(place).add(column.get_data()[row_num]); } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { this->data(place).merge( const_cast&>(this->data(rhs)).get()); } @@ -100,7 +99,8 @@ class AggregateFunctionBitmapOp final this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } @@ -109,8 +109,6 @@ class AggregateFunctionBitmapOp final column.get_data().push_back( const_cast&>(this->data(place)).get()); } - - const char* get_header_file_path() const override { return __FILE__; } }; template @@ -146,7 +144,8 @@ class AggregateFunctionBitmapCount final } } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { this->data(place).merge(const_cast(this->data(rhs)).get()); } @@ -154,7 +153,8 @@ class AggregateFunctionBitmapCount final this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } @@ -163,8 +163,6 @@ class AggregateFunctionBitmapCount final auto& column = static_cast(to); column.get_data().push_back(value_data.cardinality()); } - - const char* get_header_file_path() const override { return __FILE__; } }; AggregateFunctionPtr create_aggregate_function_bitmap_union(const std::string& name, diff --git a/be/src/vec/aggregate_functions/aggregate_function_count.h b/be/src/vec/aggregate_functions/aggregate_function_count.h index fd096dc6bed435..3d8ab796e19ba7 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_count.h +++ b/be/src/vec/aggregate_functions/aggregate_function_count.h @@ -50,11 +50,10 @@ class AggregateFunctionCount final ++data(place).count; } - void reset(AggregateDataPtr place) const override { - this->data(place).count = 0; - } + void reset(AggregateDataPtr place) const override { this->data(place).count = 0; } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { data(place).count += data(rhs).count; } @@ -62,15 +61,14 @@ class AggregateFunctionCount final write_var_uint(data(place).count, buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { read_var_uint(data(place).count, buf); } void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { assert_cast(to).get_data().push_back(data(place).count); } - - const char* get_header_file_path() const override { return __FILE__; } }; /// Simply count number of not-NULL values. @@ -90,11 +88,10 @@ class AggregateFunctionCountNotNullUnary final data(place).count += !assert_cast(*columns[0]).is_null_at(row_num); } - void reset(AggregateDataPtr place) const override { - data(place).count = 0; - } + void reset(AggregateDataPtr place) const override { data(place).count = 0; } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { data(place).count += data(rhs).count; } @@ -102,21 +99,22 @@ class AggregateFunctionCountNotNullUnary final write_var_uint(data(place).count, buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { read_var_uint(data(place).count, buf); } void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { if (to.is_nullable()) { - auto& null_column = assert_cast(to); + auto& null_column = assert_cast(to); null_column.get_null_map_data().push_back(0); - assert_cast(null_column.get_nested_column()).get_data().push_back(data(place).count); + assert_cast(null_column.get_nested_column()) + .get_data() + .push_back(data(place).count); } else { - assert_cast(to).get_data().push_back(data(place).count); + assert_cast(to).get_data().push_back(data(place).count); } } - - const char* get_header_file_path() const override { return __FILE__; } }; } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_distinct.h b/be/src/vec/aggregate_functions/aggregate_function_distinct.h index 6502b482752758..1e356867998075 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_distinct.h +++ b/be/src/vec/aggregate_functions/aggregate_function_distinct.h @@ -69,13 +69,12 @@ struct AggregateFunctionDistinctGenericData { Set::LookupResult it; bool inserted; for (const auto& elem : rhs.set) - set.emplace(ArenaKeyHolder{elem.get_value(), *arena}, it, inserted); + set.emplace(ArenaKeyHolder {elem.get_value(), *arena}, it, inserted); } void serialize(BufferWritable& buf) const { write_var_uint(set.size(), buf); - for (const auto& elem : set) - write_string_binary(elem.get_value(), buf); + for (const auto& elem : set) write_string_binary(elem.get_value(), buf); } void deserialize(BufferReadable& buf, Arena* arena) { @@ -121,7 +120,7 @@ struct AggregateFunctionDistinctMultipleGenericData : public AggregateFunctionDi Set::LookupResult it; bool inserted; - auto key_holder = SerializedKeyHolder{value, *arena}; + auto key_holder = SerializedKeyHolder {value, *arena}; set.emplace(key_holder, it, inserted); } @@ -180,7 +179,8 @@ class AggregateFunctionDistinct this->data(place).serialize(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena* arena) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena* arena) const override { this->data(place).deserialize(buf, arena); } @@ -217,8 +217,6 @@ class AggregateFunctionDistinct DataTypePtr get_return_type() const override { return nested_func->get_return_type(); } bool allocates_memory_in_arena() const override { return true; } - - const char* get_header_file_path() const override { return __FILE__; } }; } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h b/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h index f71a1f5596fceb..612b552946e064 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h @@ -17,10 +17,6 @@ #pragma once -#include -#include -#include - #include "exprs/hll_function.h" #include "olap/hll.h" #include "util/slice.h" @@ -86,7 +82,8 @@ class AggregateFunctionHLLUnionAgg this->data(place).add(column.get_data_at(row_num)); } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { this->data(place).merge(this->data(rhs)); } @@ -94,16 +91,16 @@ class AggregateFunctionHLLUnionAgg this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } - virtual void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { + virtual void insert_result_into(ConstAggregateDataPtr __restrict place, + IColumn& to) const override { auto& column = static_cast&>(to); column.get_data().push_back(this->data(place).get_cardinality()); } - - const char* get_header_file_path() const override { return __FILE__; } }; class AggregateFunctionHLLUnion final : public AggregateFunctionHLLUnionAgg { diff --git a/be/src/vec/aggregate_functions/aggregate_function_min_max.h b/be/src/vec/aggregate_functions/aggregate_function_min_max.h index 17d682339a2f71..9c2f0970df2c55 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_min_max.h +++ b/be/src/vec/aggregate_functions/aggregate_function_min_max.h @@ -35,7 +35,8 @@ struct SingleValueDataFixed { private: using Self = SingleValueDataFixed; - bool has_value = false; /// We need to remember if at least one value has been passed. This is necessary for AggregateFunctionIf. + bool has_value = + false; /// We need to remember if at least one value has been passed. This is necessary for AggregateFunctionIf. T value; public: @@ -50,7 +51,7 @@ struct SingleValueDataFixed { void reset() { if (has()) { - has_value = false; + has_value = false; } } @@ -166,10 +167,10 @@ struct SingleValueDataFixed { void reset() { if (has()) { - has_value = false; + has_value = false; } } - + void write(BufferWritable& buf) const { write_binary(has(), buf); if (has()) write_binary(value, buf); @@ -297,13 +298,13 @@ struct SingleValueDataString { void reset() { if (size != -1) { - size = -1; - capacity = 0; + size = -1; + capacity = 0; delete large_data; large_data = nullptr; } } - + void write(BufferWritable& buf) const { write_binary(size, buf); if (has()) buf.write(get_data(), size); @@ -497,11 +498,10 @@ class AggregateFunctionsSingleValue final this->data(place).change_if_better(*columns[0], row_num, arena); } - void reset(AggregateDataPtr place) const override { - this->data(place).reset(); - } + void reset(AggregateDataPtr place) const override { this->data(place).reset(); } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena* arena) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena* arena) const override { this->data(place).change_if_better(this->data(rhs), arena); } @@ -509,7 +509,8 @@ class AggregateFunctionsSingleValue final this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } @@ -518,8 +519,6 @@ class AggregateFunctionsSingleValue final void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { this->data(place).insert_result_into(to); } - - const char* get_header_file_path() const override { return __FILE__; } }; AggregateFunctionPtr create_aggregate_function_max(const std::string& name, diff --git a/be/src/vec/aggregate_functions/aggregate_function_nothing.h b/be/src/vec/aggregate_functions/aggregate_function_nothing.h index 4c7b1933e6bd0f..c0ae740be4eeb9 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_nothing.h +++ b/be/src/vec/aggregate_functions/aggregate_function_nothing.h @@ -54,7 +54,7 @@ class AggregateFunctionNothing final : public IAggregateFunctionHelper { } static void init_flag(AggregateDataPtr __restrict place) noexcept { - if constexpr (result_is_nullable) - place[0] = 0; + if constexpr (result_is_nullable) place[0] = 0; } static void set_flag(AggregateDataPtr __restrict place) noexcept { - if constexpr (result_is_nullable) - place[0] = 1; + if constexpr (result_is_nullable) place[0] = 1; } static bool get_flag(ConstAggregateDataPtr __restrict place) noexcept { @@ -117,7 +115,8 @@ class AggregateFunctionNullBase : public IAggregateFunctionHelper { size_t align_of_data() const override { return nested_function->align_of_data(); } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena* arena) const override { + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena* arena) const override { if (result_is_nullable && get_flag(rhs)) set_flag(place); nested_function->merge(nested_place(place), nested_place(rhs), arena); @@ -131,7 +130,8 @@ class AggregateFunctionNullBase : public IAggregateFunctionHelper { } } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena* arena) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena* arena) const override { bool flag = true; if (result_is_nullable) read_binary(flag, buf); if (flag) { @@ -145,10 +145,12 @@ class AggregateFunctionNullBase : public IAggregateFunctionHelper { ColumnNullable& to_concrete = assert_cast(to); if (get_flag(place)) { if (nested_function->insert_to_null_default()) { - nested_function->insert_result_into(nested_place(place), to_concrete.get_nested_column()); + nested_function->insert_result_into(nested_place(place), + to_concrete.get_nested_column()); to_concrete.get_null_map_data().push_back(0); } else { - nested_function->insert_result_into(nested_place(place), to); //want to insert into null value by self + nested_function->insert_result_into( + nested_place(place), to); //want to insert into null value by self } } else { to_concrete.insert_default(); @@ -163,8 +165,6 @@ class AggregateFunctionNullBase : public IAggregateFunctionHelper { } bool is_state() const override { return nested_function->is_state(); } - - const char* get_header_file_path() const override { return __FILE__; } }; /** There are two cases: for single argument and variadic. diff --git a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp index ba1b2ba98e095a..4844000b3ddf4c 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_simple_factory.cpp @@ -36,6 +36,7 @@ void register_aggregate_function_bitmap(AggregateFunctionSimpleFactory& factory) void register_aggregate_function_window_rank(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_window_lead_lag(AggregateFunctionSimpleFactory& factory); void register_aggregate_function_stddev_variance(AggregateFunctionSimpleFactory& factory); +void register_aggregate_function_topn(AggregateFunctionSimpleFactory& factory); AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() { static std::once_flag oc; static AggregateFunctionSimpleFactory instance; @@ -51,10 +52,11 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() { register_aggregate_function_reader(instance); // register aggregate function for agg reader register_aggregate_function_window_rank(instance); register_aggregate_function_stddev_variance(instance); - + register_aggregate_function_topn(instance); + // if you only register function with no nullable, and wants to add nullable automatically, you should place function above this line register_aggregate_function_combinator_null(instance); - + register_aggregate_function_reader_no_spread(instance); register_aggregate_function_window_lead_lag(instance); }); diff --git a/be/src/vec/aggregate_functions/aggregate_function_stddev.h b/be/src/vec/aggregate_functions/aggregate_function_stddev.h index 6cdba20032e8fb..82e8718fcd7c8a 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_stddev.h +++ b/be/src/vec/aggregate_functions/aggregate_function_stddev.h @@ -188,7 +188,8 @@ struct BaseDatadecimal { template struct PopData : Data { - using ColVecResult = std::conditional_t, ColumnDecimal, ColumnVector>; + using ColVecResult = std::conditional_t, ColumnDecimal, + ColumnVector>; void insert_result_into(IColumn& to) const { ColumnNullable& nullable_column = assert_cast(to); auto& col = static_cast(nullable_column.get_nested_column()); @@ -203,7 +204,8 @@ struct PopData : Data { template struct SampData : Data { - using ColVecResult = std::conditional_t, ColumnDecimal, ColumnVector>; + using ColVecResult = std::conditional_t, ColumnDecimal, + ColumnVector>; void insert_result_into(IColumn& to) const { ColumnNullable& nullable_column = assert_cast(to); if (this->count == 1) { @@ -278,8 +280,6 @@ class AggregateFunctionStddevSamp final void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { this->data(place).insert_result_into(to); } - - const char* get_header_file_path() const override { return __FILE__; } }; } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_sum.h b/be/src/vec/aggregate_functions/aggregate_function_sum.h index 402af36354b589..eceaf03338e8f6 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_sum.h +++ b/be/src/vec/aggregate_functions/aggregate_function_sum.h @@ -20,10 +20,6 @@ #pragma once -#include -#include -#include - #include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/column_vector.h" #include "vec/data_types/data_type_decimal.h" @@ -82,12 +78,11 @@ class AggregateFunctionSum final const auto& column = static_cast(*columns[0]); this->data(place).add(column.get_data()[row_num]); } - - void reset(AggregateDataPtr place) const override { - this->data(place).sum = {}; - } - void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { + void reset(AggregateDataPtr place) const override { this->data(place).sum = {}; } + + void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, + Arena*) const override { this->data(place).merge(this->data(rhs)); } @@ -95,7 +90,8 @@ class AggregateFunctionSum final this->data(place).write(buf); } - void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { + void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, + Arena*) const override { this->data(place).read(buf); } @@ -104,15 +100,13 @@ class AggregateFunctionSum final column.get_data().push_back(this->data(place).get()); } - const char* get_header_file_path() const override { return __FILE__; } - private: UInt32 scale; }; AggregateFunctionPtr create_aggregate_function_sum_reader(const std::string& name, - const DataTypes& argument_types, - const Array& parameters, - const bool result_is_nullable); + const DataTypes& argument_types, + const Array& parameters, + const bool result_is_nullable); } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_topn.cpp b/be/src/vec/aggregate_functions/aggregate_function_topn.cpp new file mode 100644 index 00000000000000..a8347bf02916ac --- /dev/null +++ b/be/src/vec/aggregate_functions/aggregate_function_topn.cpp @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +namespace doris::vectorized { + +template