HappenLee commented on code in PR #58666:
URL: https://github.com/apache/doris/pull/58666#discussion_r2588142131
##########
be/src/vec/aggregate_functions/aggregate_function_avg.h:
##########
@@ -112,31 +117,41 @@ class AggregateFunctionAvg final
UnaryExpression,
NullableAggregateFunction {
public:
- using ResultType = std::conditional_t<
- T == TYPE_DECIMALV2, Decimal128V2,
- std::conditional_t<is_decimal(T), typename Data::ResultType,
Float64>>;
- using ResultDataType = std::conditional_t<
- T == TYPE_DECIMALV2, DataTypeDecimalV2,
- std::conditional_t<is_decimal(T),
DataTypeDecimal<Data::ResultPType>, DataTypeFloat64>>;
+ using ResultDataType =
+ std::conditional_t<is_decimal(T),
+ typename
PrimitiveTypeTraits<Data::ResultPType>::DataType,
+ DataTypeFloat64>;
using ColVecType = typename PrimitiveTypeTraits<T>::ColumnType;
- using ColVecResult = std::conditional_t<
- T == TYPE_DECIMALV2, ColumnDecimal128V2,
- std::conditional_t<is_decimal(T),
ColumnDecimal<Data::ResultPType>, ColumnFloat64>>;
+ using ColVecResult =
+ std::conditional_t<is_decimal(T),
+ typename
PrimitiveTypeTraits<Data::ResultPType>::ColumnType,
+ ColumnFloat64>;
// The result calculated by PercentileApprox is an approximate value,
// so the underlying storage uses float. The following calls will involve
// an implicit cast to float.
using DataType = typename Data::ResultType;
+ using ResultType = std::conditional_t<is_decimal(T), DataType, Float64>;
/// ctor for native types
+ // consistent with
fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
+ static constexpr uint32_t DEFAULT_MIN_AVG_DECIMAL128_SCALE = 4;
AggregateFunctionAvg(const DataTypes& argument_types_)
: IAggregateFunctionDataHelper<Data, AggregateFunctionAvg<T,
Data>>(argument_types_),
- scale(get_decimal_scale(*argument_types_[0])) {}
+ input_scale(get_decimal_scale(*argument_types_[0])),
+ output_scale(std::max(DEFAULT_MIN_AVG_DECIMAL128_SCALE,
input_scale)) {
+ if constexpr (is_decimal(T)) {
+ multiplier =
+
ResultType(ResultDataType::get_scale_multiplier(output_scale - input_scale));
+ }
+ }
String get_name() const override { return "avg"; }
DataTypePtr get_return_type() const override {
if constexpr (is_decimal(T)) {
- return
std::make_shared<ResultDataType>(ResultDataType::max_precision(), scale);
+ return std::make_shared<ResultDataType>(
Review Comment:
we should calc the res in constructor and keep be member var
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]