diff --git a/dbms/src/AggregateFunctions/AggregateFunctionSum.cpp b/dbms/src/AggregateFunctions/AggregateFunctionSum.cpp index ebca8113e04..58fd7f6fef9 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionSum.cpp +++ b/dbms/src/AggregateFunctions/AggregateFunctionSum.cpp @@ -21,7 +21,7 @@ struct SumSimple /// @note It uses slow Decimal128 (cause we need such a variant). sumWithOverflow is faster for Decimal32/64 using ResultType = std::conditional_t, Decimal128, NearestFieldType>; using AggregateDataType = AggregateFunctionSumData; - using Function = AggregateFunctionSum; + using Function = AggregateFunctionSum; }; template @@ -29,7 +29,7 @@ struct SumSameType { using ResultType = T; using AggregateDataType = AggregateFunctionSumData; - using Function = AggregateFunctionSum; + using Function = AggregateFunctionSum; }; template @@ -37,7 +37,7 @@ struct SumKahan { using ResultType = Float64; using AggregateDataType = AggregateFunctionSumKahanData; - using Function = AggregateFunctionSum; + using Function = AggregateFunctionSum; }; template using AggregateFunctionSumSimple = typename SumSimple::Function; diff --git a/dbms/src/AggregateFunctions/AggregateFunctionSum.h b/dbms/src/AggregateFunctions/AggregateFunctionSum.h index 5170b4ddd9a..46b90555c27 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionSum.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionSum.h @@ -91,24 +91,39 @@ struct AggregateFunctionSumKahanData }; +enum AggregateFunctionSumType +{ + AggregateFunctionTypeSum, + AggregateFunctionTypeSumWithOverflow, + AggregateFunctionTypeSumKahan, +}; /// Counts the sum of the numbers. -template -class AggregateFunctionSum final : public IAggregateFunctionDataHelper> +template +class AggregateFunctionSum final : public IAggregateFunctionDataHelper> { public: using ResultDataType = std::conditional_t, DataTypeDecimal, DataTypeNumber>; using ColVecType = std::conditional_t, ColumnDecimal, ColumnVector>; using ColVecResult = std::conditional_t, ColumnDecimal, ColumnVector>; - String getName() const override { return "sum"; } + String getName() const override + { + if constexpr (Type == AggregateFunctionTypeSum) + return "sum"; + else if constexpr (Type == AggregateFunctionTypeSumWithOverflow) + return "sumWithOverflow"; + else if constexpr (Type == AggregateFunctionTypeSumKahan) + return "sumKahan"; + __builtin_unreachable(); + } AggregateFunctionSum(const DataTypes & argument_types_) - : IAggregateFunctionDataHelper>(argument_types_, {}) + : IAggregateFunctionDataHelper>(argument_types_, {}) , scale(0) {} AggregateFunctionSum(const IDataType & data_type, const DataTypes & argument_types_) - : IAggregateFunctionDataHelper>(argument_types_, {}) + : IAggregateFunctionDataHelper>(argument_types_, {}) , scale(getDecimalScale(data_type)) {} diff --git a/dbms/tests/queries/0_stateless/01098_sum.reference b/dbms/tests/queries/0_stateless/01098_sum.reference new file mode 100644 index 00000000000..bb0b1cf658d --- /dev/null +++ b/dbms/tests/queries/0_stateless/01098_sum.reference @@ -0,0 +1,3 @@ +0 +0 +0 diff --git a/dbms/tests/queries/0_stateless/01098_sum.sql b/dbms/tests/queries/0_stateless/01098_sum.sql new file mode 100644 index 00000000000..d660cd41ff1 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01098_sum.sql @@ -0,0 +1,3 @@ +select sumKahan(dummy) from remote('127.{2,3}', system.one); +select sumWithOverflow(dummy) from remote('127.{2,3}', system.one); +select sum(dummy) from remote('127.{2,3}', system.one);