github-actions[bot] commented on code in PR #68632:
URL: https://github.com/apache/doris/pull/68632#discussion_r4131617267


##########
be/src/exprs/function/array/function_array_aggregation.cpp:
##########
@@ -90,7 +90,8 @@ struct AggregateFunctionTraits<AggregateOperation::AVERAGE> {
     struct TypeTraits {
         static constexpr PrimitiveType ResultType =
                 Element == TYPE_DECIMALV2 ? TYPE_DECIMALV2 : TYPE_DOUBLE;
-        using AggregateDataType = AggregateFunctionAvgData<ResultType>;
+        // Add up the values in the same type as avg(). A double sum loses 
digits of large integers.
+        using AggregateDataType = 
AggregateFunctionAvgData<avg_sum_type(Element)>;

Review Comment:
   [P1] Prevent LARGEINT overflow before computing array_avg. This change 
accumulates every LARGEINT element in signed Int128 before converting the sum 
to double. The existing ArrayNullsafe fixture averages three near-maximum 
LARGEINTs: its correct result is about 1.7014118346046923e38, but this PR 
changes the expected output to 5.671372782015641e37 because the sum wraps. 
Valid arrays such as two maximum values can even produce a negative mean. Use 
an overflow-safe accumulation strategy that preserves the new cancellation 
precision, and cover noncancelling positive and negative extremes in the 
regression test.



-- 
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]

Reply via email to