diff --git a/.clang-tidy b/.clang-tidy index 35beea9606..7b4a2a53a0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -13,5 +13,13 @@ Checks: | readability-non-const-parameter, readability-static-accessed-through-instance, readability-redundant-smartptr-get, - readability-redundant-string-init + readability-redundant-member-init, + readability-redundant-string-cstr, + readability-redundant-string-init, + readability-braces-around-statements, + portability-simd-intrinsics, + performance-type-promotion-in-math-fn, + performance-faster-string-find, + performance-inefficient-algorithm, + performance-move-const-arg WarningsAsErrors: '*' diff --git a/be/src/vec/aggregate_functions/aggregate_function.h b/be/src/vec/aggregate_functions/aggregate_function.h index 5cf529cbdb..7506883d71 100644 --- a/be/src/vec/aggregate_functions/aggregate_function.h +++ b/be/src/vec/aggregate_functions/aggregate_function.h @@ -57,7 +57,7 @@ public: /// Get the result type. virtual DataTypePtr get_return_type() const = 0; - virtual ~IAggregateFunction() {} + virtual ~IAggregateFunction() = default; /** Create empty data for aggregation with `placement new` at the specified location. * You will have to destroy them using the `destroy` method. @@ -147,14 +147,16 @@ public: 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) + for (size_t i = 0; i < batch_size; ++i) { static_cast(this)->add(places[i] + place_offset, columns, i, arena); + } } void add_batch_single_place(size_t batch_size, AggregateDataPtr place, const IColumn** columns, Arena* arena) const override { - for (size_t i = 0; i < batch_size; ++i) + for (size_t i = 0; i < batch_size; ++i) { static_cast(this)->add(place, columns, i, arena); + } } //now this is use for sum/count/avg/min/max win function, other win function should override this function in class void add_range_single_place(int64_t partition_start, int64_t partition_end, int64_t frame_start, @@ -169,8 +171,9 @@ public: void add_batch_range(size_t batch_begin, size_t batch_end, AggregateDataPtr place, const IColumn** columns, Arena* arena, bool has_null) override { - for (size_t i = batch_begin; i <= batch_end; ++i) + for (size_t i = batch_begin; i <= batch_end; ++i) { static_cast(this)->add(place, columns, i, arena); + } } }; 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 fc68d85d64..d61c254a1e 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 @@ -31,7 +31,7 @@ AggregateFunctionPtr create_aggregate_function_approx_count_distinct( : argument_types[0]); res.reset(create_class_with_type(*argument_types[0], - argument_types)); + argument_types)); if (!res) { LOG(WARNING) << fmt::format("Illegal type {} of argument for aggregate function {}", diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg.cpp b/be/src/vec/aggregate_functions/aggregate_function_avg.cpp index 61687af3aa..51574b0c29 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_avg.cpp @@ -45,11 +45,12 @@ AggregateFunctionPtr create_aggregate_function_avg(const std::string& name, AggregateFunctionPtr res; DataTypePtr data_type = argument_types[0]; - if (is_decimal(data_type)) + if (is_decimal(data_type)) { res.reset( create_with_decimal_type(*data_type, *data_type, argument_types)); - else + } else { res.reset(create_with_numeric_type(*data_type, argument_types)); + } if (!res) { LOG(WARNING) << fmt::format("Illegal type {} of argument for aggregate function {}", diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg.h b/be/src/vec/aggregate_functions/aggregate_function_avg.h index 4aeb7fe998..0bbc935f43 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_avg.h @@ -36,9 +36,11 @@ struct AggregateFunctionAvgData { template ResultT result() const { - if constexpr (std::is_floating_point_v) - if constexpr (std::numeric_limits::is_iec559) + if constexpr (std::is_floating_point_v) { + if constexpr (std::numeric_limits::is_iec559) { return static_cast(sum) / count; /// allow division by zero + } + } if (!count) { // null is handled in AggregationNode::_get_without_key_result @@ -85,10 +87,11 @@ public: String get_name() const override { return "avg"; } DataTypePtr get_return_type() const override { - if constexpr (IsDecimalNumber) + if constexpr (IsDecimalNumber) { return std::make_shared(ResultDataType::max_precision(), scale); - else + } else { return std::make_shared(); + } } void add(AggregateDataPtr __restrict place, const IColumn** columns, size_t row_num, diff --git a/be/src/vec/aggregate_functions/aggregate_function_bitmap.cpp b/be/src/vec/aggregate_functions/aggregate_function_bitmap.cpp index d110b09e1e..e429e93f44 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_bitmap.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_bitmap.cpp @@ -28,14 +28,18 @@ static IAggregateFunction* createWithIntDataType(const DataTypes& argument_type) type = assert_cast(type)->get_nested_type().get(); } WhichDataType which(type); - if (which.idx == TypeIndex::Int8) + if (which.idx == TypeIndex::Int8) { return new AggregateFunctionTemplate>(argument_type); - if (which.idx == TypeIndex::Int16) + } + if (which.idx == TypeIndex::Int16) { return new AggregateFunctionTemplate>(argument_type); - if (which.idx == TypeIndex::Int32) + } + if (which.idx == TypeIndex::Int32) { return new AggregateFunctionTemplate>(argument_type); - if (which.idx == TypeIndex::Int64) + } + if (which.idx == TypeIndex::Int64) { return new AggregateFunctionTemplate>(argument_type); + } return nullptr; } diff --git a/be/src/vec/aggregate_functions/aggregate_function_combinator.h b/be/src/vec/aggregate_functions/aggregate_function_combinator.h index d53f3d2bea..b99b9e13c2 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_combinator.h +++ b/be/src/vec/aggregate_functions/aggregate_function_combinator.h @@ -73,7 +73,7 @@ public: const AggregateFunctionPtr& nested_function, const DataTypes& arguments, const Array& params, const bool result_is_nullable) const = 0; - virtual ~IAggregateFunctionCombinator() {} + virtual ~IAggregateFunctionCombinator() = default; }; } // namespace doris::vectorized diff --git a/be/src/vec/aggregate_functions/aggregate_function_count.h b/be/src/vec/aggregate_functions/aggregate_function_count.h index 3d8ab796e1..e2ba3768e7 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_count.h +++ b/be/src/vec/aggregate_functions/aggregate_function_count.h @@ -50,7 +50,9 @@ public: ++data(place).count; } - void reset(AggregateDataPtr place) const override { this->data(place).count = 0; } + void reset(AggregateDataPtr place) const override { + AggregateFunctionCount::data(place).count = 0; + } void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { diff --git a/be/src/vec/aggregate_functions/aggregate_function_distinct.cpp b/be/src/vec/aggregate_functions/aggregate_function_distinct.cpp index af64a3a15d..26e9e1520c 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_distinct.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_distinct.cpp @@ -18,11 +18,12 @@ // https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/AggregateFunctionDistinct.cpp // and modified by Doris +#include "vec/aggregate_functions/aggregate_function_distinct.h" + #include #include #include "vec/aggregate_functions/aggregate_function_combinator.h" -#include "vec/aggregate_functions/aggregate_function_distinct.h" #include "vec/aggregate_functions/aggregate_function_simple_factory.h" #include "vec/aggregate_functions/helpers.h" #include "vec/common/typeid_cast.h" @@ -42,29 +43,33 @@ public: return arguments; } - AggregateFunctionPtr transform_aggregate_function(const AggregateFunctionPtr& nested_function, - const DataTypes& arguments, - const Array& params, - const bool result_is_nullable) const override { + AggregateFunctionPtr transform_aggregate_function( + const AggregateFunctionPtr& nested_function, const DataTypes& arguments, + const Array& params, const bool result_is_nullable) const override { DCHECK(nested_function != nullptr); - if (nested_function == nullptr) return nullptr; - + if (nested_function == nullptr) { + return nullptr; + } + AggregateFunctionPtr res; if (arguments.size() == 1) { res.reset(create_with_numeric_type( *arguments[0], nested_function, arguments)); - if (res) return res; + if (res) { + return res; + } - if (arguments[0]->is_value_unambiguously_represented_in_contiguous_memory_region()) + if (arguments[0]->is_value_unambiguously_represented_in_contiguous_memory_region()) { return std::make_shared>>(nested_function, arguments); - else + } else { return std::make_shared>>(nested_function, arguments); + } } return std::make_shared< @@ -89,7 +94,8 @@ void register_aggregate_function_combinator_distinct(AggregateFunctionSimpleFact } auto nested_function_name = name.substr(DISTINCT_FUNCTION_PREFIX.size()); auto nested_function = factory.get(nested_function_name, transform_arguments, params); - return function_combinator->transform_aggregate_function(nested_function, types, params, result_is_nullable); + return function_combinator->transform_aggregate_function(nested_function, types, params, + result_is_nullable); }; factory.register_distinct_function_combinator(creator, DISTINCT_FUNCTION_PREFIX); } diff --git a/be/src/vec/aggregate_functions/aggregate_function_distinct.h b/be/src/vec/aggregate_functions/aggregate_function_distinct.h index 81f33bddbc..820759a7ff 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_distinct.h +++ b/be/src/vec/aggregate_functions/aggregate_function_distinct.h @@ -53,7 +53,9 @@ struct AggregateFunctionDistinctSingleNumericData { MutableColumns get_arguments(const DataTypes& argument_types) const { MutableColumns argument_columns; argument_columns.emplace_back(argument_types[0]->create_column()); - for (const auto& elem : set) argument_columns[0]->insert(elem.get_value()); + for (const auto& elem : set) { + argument_columns[0]->insert(elem.get_value()); + } return argument_columns; } @@ -68,13 +70,16 @@ struct AggregateFunctionDistinctGenericData { void merge(const Self& rhs, Arena* arena) { Set::LookupResult it; bool inserted; - for (const auto& elem : rhs.set) + for (const auto& elem : rhs.set) { 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) { @@ -101,8 +106,9 @@ struct AggregateFunctionDistinctSingleGenericData : public AggregateFunctionDist MutableColumns get_arguments(const DataTypes& argument_types) const { MutableColumns argument_columns; argument_columns.emplace_back(argument_types[0]->create_column()); - for (const auto& elem : set) + for (const auto& elem : set) { deserialize_and_insert(elem.get_value(), *argument_columns[0]); + } return argument_columns; } @@ -126,13 +132,15 @@ struct AggregateFunctionDistinctMultipleGenericData : public AggregateFunctionDi MutableColumns get_arguments(const DataTypes& argument_types) const { MutableColumns argument_columns(argument_types.size()); - for (size_t i = 0; i < argument_types.size(); ++i) + for (size_t i = 0; i < argument_types.size(); ++i) { argument_columns[i] = argument_types[i]->create_column(); + } for (const auto& elem : set) { const char* begin = elem.get_value().data; - for (auto& column : argument_columns) + for (auto& column : argument_columns) { begin = column->deserialize_and_insert_from_arena(begin); + } } return argument_columns; @@ -189,7 +197,9 @@ public: auto place = const_cast(targetplace); auto arguments = this->data(place).get_arguments(this->argument_types); ColumnRawPtrs arguments_raw(arguments.size()); - for (size_t i = 0; i < arguments.size(); ++i) arguments_raw[i] = arguments[i].get(); + for (size_t i = 0; i < arguments.size(); ++i) { + arguments_raw[i] = arguments[i].get(); + } assert(!arguments.empty()); // nested_func->add_batch_single_place(arguments[0]->size(), get_nested_place(place), arguments_raw.data(), arena); 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 26fd57eca3..e8371c11bb 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_min_max.h +++ b/be/src/vec/aggregate_functions/aggregate_function_min_max.h @@ -43,10 +43,11 @@ public: bool has() const { return has_value; } void insert_result_into(IColumn& to) const { - if (has()) + if (has()) { assert_cast&>(to).get_data().push_back(value); - else + } else { assert_cast&>(to).insert_default(); + } } void reset() { @@ -57,12 +58,16 @@ public: void write(BufferWritable& buf) const { write_binary(has(), buf); - if (has()) write_binary(value, buf); + if (has()) { + write_binary(value, buf); + } } void read(BufferReadable& buf) { read_binary(has_value, buf); - if (has()) read_binary(value, buf); + if (has()) { + read_binary(value, buf); + } } void change(const IColumn& column, size_t row_num, Arena*) { @@ -80,32 +85,36 @@ public: if (!has() || assert_cast&>(column).get_data()[row_num] < value) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_less(const Self& to, Arena* arena) { if (to.has() && (!has() || to.value < value)) { change(to, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const IColumn& column, size_t row_num, Arena* arena) { if (!has() || assert_cast&>(column).get_data()[row_num] > value) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const Self& to, Arena* arena) { if (to.has() && (!has() || to.value > value)) { change(to, arena); return true; - } else + } else { return false; + } } bool is_equal_to(const Self& to) const { return has() && to.value == value; } @@ -132,8 +141,9 @@ public: if (has()) { DecimalV2Value decimal(value); assert_cast&>(to).insert_data((const char*)&decimal, 0); - } else + } else { assert_cast&>(to).insert_default(); + } } void reset() { @@ -144,12 +154,16 @@ public: void write(BufferWritable& buf) const { write_binary(has(), buf); - if (has()) write_binary(value, buf); + if (has()) { + write_binary(value, buf); + } } void read(BufferReadable& buf) { read_binary(has_value, buf); - if (has()) read_binary(value, buf); + if (has()) { + read_binary(value, buf); + } } void change(const IColumn& column, size_t row_num, Arena*) { @@ -168,16 +182,18 @@ public: assert_cast&>(column).get_data()[row_num] < value) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_less(const Self& to, Arena* arena) { if (to.has() && (!has() || to.value < value)) { change(to, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const IColumn& column, size_t row_num, Arena* arena) { @@ -185,16 +201,18 @@ public: assert_cast&>(column).get_data()[row_num] > value) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const Self& to, Arena* arena) { if (to.has() && (!has() || to.value > value)) { change(to, arena); return true; - } else + } else { return false; + } } bool is_equal_to(const Self& to) const { return has() && to.value == value; } @@ -232,10 +250,11 @@ public: const char* get_data() const { return size <= MAX_SMALL_STRING_SIZE ? small_data : large_data; } void insert_result_into(IColumn& to) const { - if (has()) + if (has()) { assert_cast(to).insert_data(get_data(), size); - else + } else { assert_cast(to).insert_default(); + } } void reset() { @@ -249,7 +268,9 @@ public: void write(BufferWritable& buf) const { write_binary(size, buf); - if (has()) buf.write(get_data(), size); + if (has()) { + buf.write(get_data(), size); + } } void read(BufferReadable& buf) { @@ -262,7 +283,9 @@ public: size = rhs_size; - if (size > 0) buf.read(small_data, size); + if (size > 0) { + buf.read(small_data, size); + } } else { if (capacity < rhs_size) { capacity = static_cast(round_up_to_power_of_two_or_zero(rhs_size)); @@ -316,8 +339,9 @@ public: assert_cast(column).get_data_at(row_num) < get_string_ref()) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const IColumn& column, size_t row_num, Arena* arena) { @@ -325,24 +349,27 @@ public: assert_cast(column).get_data_at(row_num) > get_string_ref()) { change(column, row_num, arena); return true; - } else + } else { return false; + } } bool change_if_less(const Self& to, Arena* arena) { if (to.has() && (!has() || to.get_string_ref() < get_string_ref())) { change(to, arena); return true; - } else + } else { return false; + } } bool change_if_greater(const Self& to, Arena* arena) { if (to.has() && (!has() || to.get_string_ref() > get_string_ref())) { change(to, arena); return true; - } else + } else { return false; + } } bool is_equal_to(const Self& to) const { diff --git a/be/src/vec/aggregate_functions/aggregate_function_null.cpp b/be/src/vec/aggregate_functions/aggregate_function_null.cpp index e28287f45e..495cefcb84 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_null.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_null.cpp @@ -39,15 +39,18 @@ public: DataTypes transform_arguments(const DataTypes& arguments) const override { size_t size = arguments.size(); DataTypes res(size); - for (size_t i = 0; i < size; ++i) res[i] = remove_nullable(arguments[i]); + for (size_t i = 0; i < size; ++i) { + res[i] = remove_nullable(arguments[i]); + } return res; } - AggregateFunctionPtr transform_aggregate_function(const AggregateFunctionPtr& nested_function, - const DataTypes& arguments, - const Array& params, - const bool result_is_nullable) const override { - if (nested_function == nullptr) return nullptr; + AggregateFunctionPtr transform_aggregate_function( + const AggregateFunctionPtr& nested_function, const DataTypes& arguments, + const Array& params, const bool result_is_nullable) const override { + if (nested_function == nullptr) { + return nullptr; + } bool has_null_types = false; for (const auto& arg_type : arguments) { @@ -57,22 +60,26 @@ public: } } - if (has_null_types) return std::make_shared(arguments, params); + if (has_null_types) { + return std::make_shared(arguments, params); + } if (arguments.size() == 1) { - if (result_is_nullable) + if (result_is_nullable) { return std::make_shared>(nested_function, arguments, params); - else + } else { return std::make_shared>(nested_function, arguments, params); + } } else { - if (result_is_nullable) + if (result_is_nullable) { return std::make_shared>(nested_function, arguments, params); - else + } else { return std::make_shared>(nested_function, arguments, params); + } } } }; @@ -84,7 +91,8 @@ void register_aggregate_function_combinator_null(AggregateFunctionSimpleFactory& auto function_combinator = std::make_shared(); auto transform_arguments = function_combinator->transform_arguments(types); auto nested_function = factory.get(name, transform_arguments, params); - return function_combinator->transform_aggregate_function(nested_function, types, params, result_is_nullable); + return function_combinator->transform_aggregate_function(nested_function, types, params, + result_is_nullable); }; factory.register_nullable_function_combinator(creator); } diff --git a/be/src/vec/aggregate_functions/aggregate_function_null.h b/be/src/vec/aggregate_functions/aggregate_function_null.h index 55e910088d..5b804b82a7 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_null.h +++ b/be/src/vec/aggregate_functions/aggregate_function_null.h @@ -62,15 +62,19 @@ protected: } static void init_flag(AggregateDataPtr __restrict place) noexcept { - if constexpr (result_is_nullable) place[0] = 0; + if constexpr (result_is_nullable) { + place[0] = false; + } } static void set_flag(AggregateDataPtr __restrict place) noexcept { - if constexpr (result_is_nullable) place[0] = 1; + if constexpr (result_is_nullable) { + place[0] = true; + } } static bool get_flag(ConstAggregateDataPtr __restrict place) noexcept { - return result_is_nullable ? place[0] : 1; + return result_is_nullable ? place[0] : true; } public: @@ -78,10 +82,11 @@ public: const Array& params) : IAggregateFunctionHelper(arguments, params), nested_function {nested_function_} { - if (result_is_nullable) + if (result_is_nullable) { prefix_size = nested_function->align_of_data(); - else + } else { prefix_size = 0; + } } String get_name() const override { @@ -117,14 +122,18 @@ public: void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena* arena) const override { - if (result_is_nullable && get_flag(rhs)) set_flag(place); + if (result_is_nullable && get_flag(rhs)) { + set_flag(place); + } nested_function->merge(nested_place(place), nested_place(rhs), arena); } void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { bool flag = get_flag(place); - if (result_is_nullable) write_binary(flag, buf); + if (result_is_nullable) { + write_binary(flag, buf); + } if (flag) { nested_function->serialize(nested_place(place), buf); } @@ -133,7 +142,9 @@ public: void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena* arena) const override { bool flag = true; - if (result_is_nullable) read_binary(flag, buf); + if (result_is_nullable) { + read_binary(flag, buf); + } if (flag) { set_flag(place); nested_function->deserialize(nested_place(place), buf, arena); @@ -248,8 +259,9 @@ public: size_t(MAX_ARGS)); } - for (size_t i = 0; i < number_of_arguments; ++i) + for (size_t i = 0; i < number_of_arguments; ++i) { is_nullable[i] = arguments[i]->is_nullable(); + } } void add(AggregateDataPtr __restrict place, const IColumn** columns, size_t row_num, @@ -267,8 +279,9 @@ public: return; } nested_columns[i] = &nullable_col.get_nested_column(); - } else + } else { nested_columns[i] = columns[i]; + } } this->set_flag(place); diff --git a/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.h b/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.h index 3e5576b84c..cca176784c 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.h +++ b/be/src/vec/aggregate_functions/aggregate_function_percentile_approx.h @@ -124,25 +124,28 @@ public: return make_nullable(std::make_shared()); } - void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } + void reset(AggregateDataPtr __restrict place) const override { + AggregateFunctionPercentileApprox::data(place).reset(); + } void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { - this->data(place).merge(this->data(rhs)); + AggregateFunctionPercentileApprox::data(place).merge( + AggregateFunctionPercentileApprox::data(rhs)); } void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { - this->data(place).write(buf); + AggregateFunctionPercentileApprox::data(place).write(buf); } void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { - this->data(place).read(buf); + AggregateFunctionPercentileApprox::data(place).read(buf); } void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { ColumnNullable& nullable_column = assert_cast(to); - double result = this->data(place).get(); + double result = AggregateFunctionPercentileApprox::data(place).get(); if (std::isnan(result)) { nullable_column.insert_default(); @@ -305,28 +308,31 @@ public: const auto& sources = static_cast&>(*columns[0]); const auto& quantile = static_cast&>(*columns[1]); - this->data(place).add(sources.get_int(row_num), quantile.get_float64(row_num)); + AggregateFunctionPercentile::data(place).add(sources.get_int(row_num), + quantile.get_float64(row_num)); } - void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } + void reset(AggregateDataPtr __restrict place) const override { + AggregateFunctionPercentile::data(place).reset(); + } void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena*) const override { - this->data(place).merge(this->data(rhs)); + AggregateFunctionPercentile::data(place).merge(AggregateFunctionPercentile::data(rhs)); } void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { - this->data(place).write(buf); + AggregateFunctionPercentile::data(place).write(buf); } void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, Arena*) const override { - this->data(place).read(buf); + AggregateFunctionPercentile::data(place).read(buf); } void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { auto& col = assert_cast&>(to); - col.insert_value(this->data(place).get()); + col.insert_value(AggregateFunctionPercentile::data(place).get()); } }; diff --git a/be/src/vec/aggregate_functions/aggregate_function_stddev.h b/be/src/vec/aggregate_functions/aggregate_function_stddev.h index 882123231e..d03774b26f 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_stddev.h +++ b/be/src/vec/aggregate_functions/aggregate_function_stddev.h @@ -28,7 +28,7 @@ namespace doris::vectorized { template struct BaseData { BaseData() : mean(0.0), m2(0.0), count(0) {} - virtual ~BaseData() {} + virtual ~BaseData() = default; void write(BufferWritable& buf) const { write_binary(mean, buf); @@ -99,7 +99,7 @@ struct BaseData { template struct BaseDatadecimal { BaseDatadecimal() : mean(0), m2(0), count(0) {} - virtual ~BaseDatadecimal() {} + virtual ~BaseDatadecimal() = default; void write(BufferWritable& buf) const { write_binary(mean, buf); @@ -236,10 +236,12 @@ struct SampData : Data { template class AggregateFunctionSampVariance - : public IAggregateFunctionDataHelper> { + : public IAggregateFunctionDataHelper< + Data, AggregateFunctionSampVariance> { public: AggregateFunctionSampVariance(const DataTypes& argument_types_) - : IAggregateFunctionDataHelper>( + : IAggregateFunctionDataHelper< + Data, AggregateFunctionSampVariance>( argument_types_, {}) {} String get_name() const override { return Data::name(); } @@ -292,7 +294,7 @@ public: //samp function it's always nullables, it's need to handle nullable column //so return type and add function should processing null values template -class AggregateFunctionSamp final: public AggregateFunctionSampVariance { +class AggregateFunctionSamp final : public AggregateFunctionSampVariance { public: AggregateFunctionSamp(const DataTypes& argument_types_) : AggregateFunctionSampVariance(argument_types_) {} @@ -300,7 +302,7 @@ public: //pop function have use AggregateFunctionNullBase function, so needn't processing null values template -class AggregateFunctionPop final: public AggregateFunctionSampVariance { +class AggregateFunctionPop final : public AggregateFunctionSampVariance { public: AggregateFunctionPop(const DataTypes& argument_types_) : AggregateFunctionSampVariance(argument_types_) {} diff --git a/be/src/vec/aggregate_functions/aggregate_function_sum.cpp b/be/src/vec/aggregate_functions/aggregate_function_sum.cpp index f7127e7b63..60313f6547 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_sum.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_sum.cpp @@ -50,10 +50,11 @@ AggregateFunctionPtr create_aggregate_function_sum(const std::string& name, AggregateFunctionPtr res; DataTypePtr data_type = argument_types[0]; - if (is_decimal(data_type)) + if (is_decimal(data_type)) { res.reset(create_with_decimal_type(*data_type, *data_type, argument_types)); - else + } else { res.reset(create_with_numeric_type(*data_type, argument_types)); + } if (!res) { LOG(WARNING) << fmt::format("Illegal type {} of argument for aggregate function {}", diff --git a/be/src/vec/aggregate_functions/aggregate_function_sum.h b/be/src/vec/aggregate_functions/aggregate_function_sum.h index eceaf03338..9c5bdfc3bf 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_sum.h +++ b/be/src/vec/aggregate_functions/aggregate_function_sum.h @@ -67,10 +67,11 @@ public: scale(get_decimal_scale(data_type)) {} DataTypePtr get_return_type() const override { - if constexpr (IsDecimalNumber) + if constexpr (IsDecimalNumber) { return std::make_shared(ResultDataType::max_precision(), scale); - else + } else { return std::make_shared(); + } } void add(AggregateDataPtr __restrict place, const IColumn** columns, size_t row_num, diff --git a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp index 0258858655..f90b4ba4d9 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp @@ -48,12 +48,14 @@ AggregateFunctionPtr create_aggregate_function_uniq(const std::string& name, WhichDataType which(argument_type); // TODO: DateType - if (res) + if (res) { return res; - else if (which.is_decimal()) - return std::make_shared>>(argument_types); - else if (which.is_string_or_fixed_string()) + } else if (which.is_decimal()) { + return std::make_shared>>( + argument_types); + } else if (which.is_string_or_fixed_string()) { return std::make_shared>>(argument_types); + } } return nullptr; diff --git a/be/src/vec/aggregate_functions/aggregate_function_window.cpp b/be/src/vec/aggregate_functions/aggregate_function_window.cpp index c40f2bce53..b96f241e51 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window.cpp +++ b/be/src/vec/aggregate_functions/aggregate_function_window.cpp @@ -83,9 +83,10 @@ static IAggregateFunction* create_function_single_value(const String& name, return new AggregateFunctionTemplate< Data>>(argument_types); } - if (which.is_string_or_fixed_string()) + if (which.is_string_or_fixed_string()) { return new AggregateFunctionTemplate< Data>>(argument_types); + } DCHECK(false) << "with unknowed type, failed in create_aggregate_function_leadlag"; return nullptr; } diff --git a/be/src/vec/aggregate_functions/aggregate_function_window.h b/be/src/vec/aggregate_functions/aggregate_function_window.h index d7e75981d0..133efe7ea0 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window.h +++ b/be/src/vec/aggregate_functions/aggregate_function_window.h @@ -53,7 +53,9 @@ public: ++data(place).count; } - void reset(AggregateDataPtr place) const override { this->data(place).count = 0; } + void reset(AggregateDataPtr place) const override { + WindowFunctionRowNumber::data(place).count = 0; + } void insert_result_into(ConstAggregateDataPtr place, IColumn& to) const override { assert_cast(to).get_data().push_back(data(place).count); @@ -87,17 +89,17 @@ public: int64_t frame_end, AggregateDataPtr place, const IColumn** columns, Arena* arena) const override { int64_t peer_group_count = frame_end - frame_start; - if (this->data(place).peer_group_start != frame_start) { - this->data(place).peer_group_start = frame_start; - this->data(place).rank += this->data(place).count; + if (WindowFunctionRank::data(place).peer_group_start != frame_start) { + WindowFunctionRank::data(place).peer_group_start = frame_start; + WindowFunctionRank::data(place).rank += WindowFunctionRank::data(place).count; } - this->data(place).count = peer_group_count; + WindowFunctionRank::data(place).count = peer_group_count; } void reset(AggregateDataPtr place) const override { - this->data(place).rank = 0; - this->data(place).count = 1; - this->data(place).peer_group_start = -1; + WindowFunctionRank::data(place).rank = 0; + WindowFunctionRank::data(place).count = 1; + WindowFunctionRank::data(place).peer_group_start = -1; } void insert_result_into(ConstAggregateDataPtr place, IColumn& to) const override { @@ -130,15 +132,15 @@ public: void add_range_single_place(int64_t partition_start, int64_t partition_end, int64_t frame_start, int64_t frame_end, AggregateDataPtr place, const IColumn** columns, Arena* arena) const override { - if (this->data(place).peer_group_start != frame_start) { - this->data(place).peer_group_start = frame_start; - this->data(place).rank++; + if (WindowFunctionDenseRank::data(place).peer_group_start != frame_start) { + WindowFunctionDenseRank::data(place).peer_group_start = frame_start; + WindowFunctionDenseRank::data(place).rank++; } } void reset(AggregateDataPtr place) const override { - this->data(place).rank = 0; - this->data(place).peer_group_start = -1; + WindowFunctionDenseRank::data(place).rank = 0; + WindowFunctionDenseRank::data(place).peer_group_start = -1; } void insert_result_into(ConstAggregateDataPtr place, IColumn& to) const override { @@ -357,9 +359,7 @@ struct WindowFunctionLastData : Data { frame_end = std::min(frame_end, partition_end); this->set_value(columns, frame_end - 1); } - void add(int64_t row, const IColumn** columns) { - this->set_value(columns, row); - } + void add(int64_t row, const IColumn** columns) { this->set_value(columns, row); } static const char* name() { return "last_value"; } }; diff --git a/be/src/vec/aggregate_functions/factory_helpers.h b/be/src/vec/aggregate_functions/factory_helpers.h index 95b5538441..b93d422d27 100644 --- a/be/src/vec/aggregate_functions/factory_helpers.h +++ b/be/src/vec/aggregate_functions/factory_helpers.h @@ -42,7 +42,9 @@ inline void assert_binary(const std::string& name, const DataTypes& argument_typ template inline void assert_arity_at_most(const std::string& name, const DataTypes& argument_types) { - if (argument_types.size() <= maximal_arity) return; + if (argument_types.size() <= maximal_arity) { + return; + } if constexpr (maximal_arity == 0) { LOG(FATAL) << fmt::format("Aggregate function {} cannot have arguments", name); diff --git a/be/src/vec/aggregate_functions/helpers.h b/be/src/vec/aggregate_functions/helpers.h index 02b49a8cb0..fce6e82cb7 100644 --- a/be/src/vec/aggregate_functions/helpers.h +++ b/be/src/vec/aggregate_functions/helpers.h @@ -49,10 +49,12 @@ static IAggregateFunction* create_with_numeric_type(const IDataType& argument_ty return new AggregateFunctionTemplate(std::forward(args)...); FOR_NUMERIC_TYPES(DISPATCH) #undef DISPATCH - if (which.idx == TypeIndex::Enum8) + if (which.idx == TypeIndex::Enum8) { return new AggregateFunctionTemplate(std::forward(args)...); - if (which.idx == TypeIndex::Enum16) + } + if (which.idx == TypeIndex::Enum16) { return new AggregateFunctionTemplate(std::forward(args)...); + } return nullptr; } @@ -66,10 +68,12 @@ static IAggregateFunction* create_with_numeric_type(const IDataType& argument_ty return new AggregateFunctionTemplate(std::forward(args)...); FOR_NUMERIC_TYPES(DISPATCH) #undef DISPATCH - if (which.idx == TypeIndex::Enum8) + if (which.idx == TypeIndex::Enum8) { return new AggregateFunctionTemplate(std::forward(args)...); - if (which.idx == TypeIndex::Enum16) + } + if (which.idx == TypeIndex::Enum16) { return new AggregateFunctionTemplate(std::forward(args)...); + } return nullptr; } @@ -83,10 +87,12 @@ static IAggregateFunction* create_with_numeric_type(const IDataType& argument_ty return new AggregateFunctionTemplate(std::forward(args)...); FOR_NUMERIC_TYPES(DISPATCH) #undef DISPATCH - if (which.idx == TypeIndex::Enum8) + if (which.idx == TypeIndex::Enum8) { return new AggregateFunctionTemplate(std::forward(args)...); - if (which.idx == TypeIndex::Enum16) + } + if (which.idx == TypeIndex::Enum16) { return new AggregateFunctionTemplate(std::forward(args)...); + } return nullptr; } @@ -100,10 +106,12 @@ static IAggregateFunction* create_with_numeric_type(const IDataType& argument_ty return new AggregateFunctionTemplate>(std::forward(args)...); FOR_NUMERIC_TYPES(DISPATCH) #undef DISPATCH - if (which.idx == TypeIndex::Enum8) + if (which.idx == TypeIndex::Enum8) { return new AggregateFunctionTemplate>(std::forward(args)...); - if (which.idx == TypeIndex::Enum16) + } + if (which.idx == TypeIndex::Enum16) { return new AggregateFunctionTemplate>(std::forward(args)...); + } return nullptr; } @@ -127,14 +135,18 @@ template