yiguolei commented on code in PR #54582:
URL: https://github.com/apache/doris/pull/54582#discussion_r2302583442


##########
be/src/vec/aggregate_functions/aggregate_function_product.h:
##########
@@ -38,14 +38,42 @@ template <PrimitiveType T>
 struct AggregateFunctionProductData {
     typename PrimitiveTypeTraits<T>::ColumnItemType product {};
 
+    void add_impl(typename PrimitiveTypeTraits<T>::ColumnItemType value,
+                  typename PrimitiveTypeTraits<T>::ColumnItemType& 
product_ref) {
+        if constexpr (std::is_integral_v<typename 
PrimitiveTypeTraits<T>::ColumnItemType>) {
+            typename PrimitiveTypeTraits<T>::ColumnItemType new_product;
+            if (__builtin_expect(__builtin_mul_overflow(product_ref, value, 
&new_product), false)) {
+                // if overflow, set product to infinity to keep the same 
behavior with double type
+                throw Exception(ErrorCode::INTERNAL_ERROR,
+                                "Product overflow for type {} and value {} * 
{}", T, value,
+                                product_ref);
+            } else {
+                product_ref = new_product;
+            }
+        } else if constexpr (std::is_floating_point_v<
+                                     typename 
PrimitiveTypeTraits<T>::ColumnItemType>) {
+            if (__builtin_expect(std::isinf(product_ref * value), false)) {
+                throw Exception(ErrorCode::INTERNAL_ERROR,
+                                "Product overflow for type {} and value {} * 
{}", T, value,

Review Comment:
   trino 或者 pg,对于float /double 类型计算溢出的时候,是返回exception?还是返回inf?



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