From c8833d6ebade8b13fdab592bd436f5406621384a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Thu, 14 Nov 2024 12:49:41 +0100 Subject: [PATCH] Revert "Remove ridiculous code bloat" --- .../AggregateFunctionDeltaSumTimestamp.cpp | 68 ++++-------------- src/AggregateFunctions/Helpers.h | 70 ++++++++++++++++++- 2 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionDeltaSumTimestamp.cpp b/src/AggregateFunctions/AggregateFunctionDeltaSumTimestamp.cpp index ad1fecac784..5819c533fd9 100644 --- a/src/AggregateFunctions/AggregateFunctionDeltaSumTimestamp.cpp +++ b/src/AggregateFunctions/AggregateFunctionDeltaSumTimestamp.cpp @@ -22,13 +22,6 @@ namespace ErrorCodes namespace { -/** Due to a lack of proper code review, this code was contributed with a multiplication of template instantiations - * over all pairs of data types, and we deeply regret that. - * - * We cannot remove all combinations, because the binary representation of serialized data has to remain the same, - * but we can partially heal the wound by treating unsigned and signed data types in the same way. - */ - template struct AggregationFunctionDeltaSumTimestampData { @@ -44,22 +37,23 @@ template class AggregationFunctionDeltaSumTimestamp final : public IAggregateFunctionDataHelper< AggregationFunctionDeltaSumTimestampData, - AggregationFunctionDeltaSumTimestamp> + AggregationFunctionDeltaSumTimestamp + > { public: AggregationFunctionDeltaSumTimestamp(const DataTypes & arguments, const Array & params) : IAggregateFunctionDataHelper< AggregationFunctionDeltaSumTimestampData, - AggregationFunctionDeltaSumTimestamp>{arguments, params, createResultType()} - { - } + AggregationFunctionDeltaSumTimestamp + >{arguments, params, createResultType()} + {} AggregationFunctionDeltaSumTimestamp() : IAggregateFunctionDataHelper< AggregationFunctionDeltaSumTimestampData, - AggregationFunctionDeltaSumTimestamp>{} - { - } + AggregationFunctionDeltaSumTimestamp + >{} + {} bool allocatesMemoryInArena() const override { return false; } @@ -69,8 +63,8 @@ public: void NO_SANITIZE_UNDEFINED ALWAYS_INLINE add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena *) const override { - auto value = unalignedLoad(columns[0]->getRawData().data() + row_num * sizeof(ValueType)); - auto ts = unalignedLoad(columns[1]->getRawData().data() + row_num * sizeof(TimestampType)); + auto value = assert_cast &>(*columns[0]).getData()[row_num]; + auto ts = assert_cast &>(*columns[1]).getData()[row_num]; auto & data = this->data(place); @@ -178,48 +172,10 @@ public: void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override { - static_cast(to).template insertRawData( - reinterpret_cast(&this->data(place).sum)); + assert_cast &>(to).getData().push_back(this->data(place).sum); } }; - -template class AggregateFunctionTemplate, typename... TArgs> -IAggregateFunction * createWithTwoTypesSecond(const IDataType & second_type, TArgs && ... args) -{ - WhichDataType which(second_type); - - if (which.idx == TypeIndex::UInt32) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::UInt64) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::Int32) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::Int64) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::Float32) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::Float64) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::Date) return new AggregateFunctionTemplate(args...); - if (which.idx == TypeIndex::DateTime) return new AggregateFunctionTemplate(args...); - - return nullptr; -} - -template