From 7426542b8b5689238b9ca0b43bebea6d8bfb42c3 Mon Sep 17 00:00:00 2001 From: akonyaev Date: Wed, 23 Oct 2019 11:22:51 +0300 Subject: [PATCH] up precision for avg result to max of type --- dbms/src/AggregateFunctions/AggregateFunctionAvg.h | 5 +---- dbms/src/DataTypes/DataTypesDecimal.h | 11 ----------- .../00700_decimal_empty_aggregates.reference | 6 +++--- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/dbms/src/AggregateFunctions/AggregateFunctionAvg.h b/dbms/src/AggregateFunctions/AggregateFunctionAvg.h index 110b0b38839..13aa9157706 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionAvg.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionAvg.h @@ -52,14 +52,12 @@ public: AggregateFunctionAvg(const DataTypes & argument_types_) : IAggregateFunctionDataHelper>(argument_types_, {}) , scale(0) - , precision(0) {} /// ctor for Decimals AggregateFunctionAvg(const IDataType & data_type, const DataTypes & argument_types_) : IAggregateFunctionDataHelper>(argument_types_, {}) , scale(getDecimalScale(data_type)) - , precision(getDecimalPrecision(data_type)) {} String getName() const override { return "avg"; } @@ -67,7 +65,7 @@ public: DataTypePtr getReturnType() const override { if constexpr (IsDecimalNumber) - return std::make_shared(precision, scale); + return std::make_shared(ResultDataType::maxPrecision(), scale); else return std::make_shared(); } @@ -107,7 +105,6 @@ public: private: UInt32 scale; - UInt32 precision; }; diff --git a/dbms/src/DataTypes/DataTypesDecimal.h b/dbms/src/DataTypes/DataTypesDecimal.h index 2626db5db8a..e59a2b6e3fd 100644 --- a/dbms/src/DataTypes/DataTypesDecimal.h +++ b/dbms/src/DataTypes/DataTypesDecimal.h @@ -243,17 +243,6 @@ inline UInt32 getDecimalScale(const IDataType & data_type, UInt32 default_value return default_value; } -inline UInt32 getDecimalPrecision(const IDataType & data_type, UInt32 default_value = std::numeric_limits::max()) - { - if (auto * decimal_type = checkDecimal(data_type)) - return decimal_type->getPrecision(); - if (auto * decimal_type = checkDecimal(data_type)) - return decimal_type->getPrecision(); - if (auto * decimal_type = checkDecimal(data_type)) - return decimal_type->getPrecision(); - return default_value; - } - /// template constexpr bool IsDataTypeDecimal = false; diff --git a/dbms/tests/queries/0_stateless/00700_decimal_empty_aggregates.reference b/dbms/tests/queries/0_stateless/00700_decimal_empty_aggregates.reference index a52fc64e29d..580cf0e26b7 100644 --- a/dbms/tests/queries/0_stateless/00700_decimal_empty_aggregates.reference +++ b/dbms/tests/queries/0_stateless/00700_decimal_empty_aggregates.reference @@ -5,9 +5,9 @@ 0.0000 0.0000000 0.00000000 0.0000 0.0000000 0.00000000 0.0000 0.0000000 0.00000000 0.0000 0.0000000 0.00000000 0.0000 0.0000000 0.00000000 0.0000 0.0000000 0.00000000 -0.0000 0.0000000 0.00000000 Decimal(6, 4) Decimal(16, 7) Decimal(20, 8) -0.0000 0.0000000 0.00000000 Decimal(6, 4) Decimal(16, 7) Decimal(20, 8) -0.0000 0.0000000 0.00000000 Decimal(6, 4) Decimal(16, 7) Decimal(20, 8) +0.0000 0.0000000 0.00000000 Decimal(9, 4) Decimal(18, 7) Decimal(38, 8) +0.0000 0.0000000 0.00000000 Decimal(9, 4) Decimal(18, 7) Decimal(38, 8) +0.0000 0.0000000 0.00000000 Decimal(9, 4) Decimal(18, 7) Decimal(38, 8) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) 0 0 0 0 0 0