mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
up precision for avg result to max of type
This commit is contained in:
parent
6d0dbf7e95
commit
7426542b8b
@ -52,14 +52,12 @@ public:
|
||||
AggregateFunctionAvg(const DataTypes & argument_types_)
|
||||
: IAggregateFunctionDataHelper<Data, AggregateFunctionAvg<T, Data>>(argument_types_, {})
|
||||
, scale(0)
|
||||
, precision(0)
|
||||
{}
|
||||
|
||||
/// ctor for Decimals
|
||||
AggregateFunctionAvg(const IDataType & data_type, const DataTypes & argument_types_)
|
||||
: IAggregateFunctionDataHelper<Data, AggregateFunctionAvg<T, Data>>(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<T>)
|
||||
return std::make_shared<ResultDataType>(precision, scale);
|
||||
return std::make_shared<ResultDataType>(ResultDataType::maxPrecision(), scale);
|
||||
else
|
||||
return std::make_shared<ResultDataType>();
|
||||
}
|
||||
@ -107,7 +105,6 @@ public:
|
||||
|
||||
private:
|
||||
UInt32 scale;
|
||||
UInt32 precision;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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<UInt32>::max())
|
||||
{
|
||||
if (auto * decimal_type = checkDecimal<Decimal32>(data_type))
|
||||
return decimal_type->getPrecision();
|
||||
if (auto * decimal_type = checkDecimal<Decimal64>(data_type))
|
||||
return decimal_type->getPrecision();
|
||||
if (auto * decimal_type = checkDecimal<Decimal128>(data_type))
|
||||
return decimal_type->getPrecision();
|
||||
return default_value;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
template <typename DataType> constexpr bool IsDataTypeDecimal = false;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user