You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "jacktengg (via GitHub)" <gi...@apache.org> on 2023/11/30 01:41:29 UTC

[PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

jacktengg opened a new pull request, #27787:
URL: https://github.com/apache/doris/pull/27787

   ## Proposed changes
   
   Issue Number: close #xxx
   
   FE changes from #27492
   
   1. use new way for decimal arithmetic precision promotion
   2. throw exception if it overflows for decimal arithmetics
   3. throw exception if it overflows when casting among number types
   
   <!--Describe your changes.-->
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1410083307


##########
be/src/vec/core/types.h:
##########
@@ -700,83 +700,9 @@ struct Decimal<wide::Int256> {
         return *this;
     }
 
-    static constexpr int max_string_length() {
-        constexpr auto precision =
-                std::is_same_v<T, Int32>
-                        ? BeConsts::MAX_DECIMAL32_PRECISION
-                        : (std::is_same_v<T, Int64>
-                                   ? BeConsts::MAX_DECIMAL64_PRECISION
-                                   : (std::is_same_v<T, Int128>
-                                              ? BeConsts::MAX_DECIMAL128_PRECISION
-                                              : BeConsts::MAX_DECIMAL256_PRECISION));
-        return precision + 1 // Add a space for decimal place
-               + 1           // Add a space for leading 0
-               + 1;          // Add a space for negative sign
-    }
+    static constexpr int max_string_length() { return max_decimal_string_length<T>(); }
 
-    std::string to_string(UInt32 scale) const {
-        if (value == std::numeric_limits<T>::min()) {
-            if constexpr (std::is_same_v<T, wide::Int256>) {
-                std::string res {wide::to_string(value)};
-                res.insert(res.size() - scale, ".");
-                return res;
-            } else {
-                fmt::memory_buffer buffer;
-                fmt::format_to(buffer, "{}", value);
-                std::string res {buffer.data(), buffer.size()};
-                res.insert(res.size() - scale, ".");
-                return res;
-            }
-        }
-
-        static constexpr auto precision =
-                std::is_same_v<T, Int32>
-                        ? BeConsts::MAX_DECIMAL32_PRECISION
-                        : (std::is_same_v<T, Int64>
-                                   ? BeConsts::MAX_DECIMAL64_PRECISION
-                                   : (std::is_same_v<T, Int128>
-                                              ? BeConsts::MAX_DECIMAL128_PRECISION
-                                              : BeConsts::MAX_DECIMAL256_PRECISION));
-        bool is_nagetive = value < 0;
-        int max_result_length = precision + (scale > 0) // Add a space for decimal place
-                                + (scale == precision)  // Add a space for leading 0
-                                + (is_nagetive);        // Add a space for negative sign
-        std::string str = std::string(max_result_length, '0');
-
-        T abs_value = value;
-        int pos = 0;
-
-        if (is_nagetive) {
-            abs_value = -value;
-            str[pos++] = '-';
-        }
-
-        T whole_part = abs_value;
-        T frac_part;
-        if (scale) {
-            whole_part = abs_value / decimal_scale_multiplier<T>(scale);
-            frac_part = abs_value % decimal_scale_multiplier<T>(scale);
-        }
-        if constexpr (std::is_same_v<T, wide::Int256>) {
-            std::string num_str {wide::to_string(whole_part)};
-            auto end = fmt::format_to(str.data() + pos, "{}", num_str);
-            pos = end - str.data();
-        } else {
-            auto end = fmt::format_to(str.data() + pos, "{}", whole_part);
-            pos = end - str.data();
-        }
-
-        if (scale) {
-            str[pos++] = '.';
-            for (auto end_pos = pos + scale - 1; end_pos >= pos && frac_part > 0;
-                 --end_pos, frac_part /= 10) {
-                str[end_pos] += (int)(frac_part % 10);
-            }
-        }
-
-        str.resize(pos + scale);
-        return str;
-    }
+    std::string to_string(UInt32 scale) const { return decimal_to_string(value, scale); }

Review Comment:
   maybe not refactor these code, because we need pick this PR to 2.0



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1837696933

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1835265761

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1414179018


##########
be/src/vec/functions/function_binary_arithmetic.h:
##########
@@ -364,121 +400,188 @@ struct DecimalBinaryOperation {
         }
     }
 
-    static ColumnPtr adapt_decimal_constant_constant(A a, B b, DataTypePtr res_data_type) {
+public:
+    static ColumnPtr adapt_decimal_constant_constant(A a, B b, const ResultType& max_result_number,
+                                                     const ResultType& scale_diff_multiplier,
+                                                     DataTypePtr res_data_type) {
         auto column_result = ColumnDecimal<ResultType>::create(
                 1, assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(1, 0);
             column_result->get_element(0) = constant_constant(a, b, null_map->get_element(0));
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
-            column_result->get_element(0) = constant_constant(a, b);
+            column_result->get_element(0) =
+                    constant_constant(a, b, max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_vector_constant(ColumnPtr column_left, B b,
+                                                   const ResultType& max_result_number,
+                                                   const ResultType& scale_diff_multiplier,
                                                    DataTypePtr res_data_type) {
         auto column_left_ptr = check_and_get_column<typename Traits::ColumnVectorA>(column_left);
         auto column_result = ColumnDecimal<ResultType>::create(
                 column_left->size(),
                 assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
         DCHECK(column_left_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_left->size(), 0);
             vector_constant(column_left_ptr->get_data().data(), b, column_result->get_data().data(),
                             null_map->get_data(), column_left->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             vector_constant(column_left_ptr->get_data().data(), b, column_result->get_data().data(),
-                            column_left->size());
+                            column_left->size(), max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_constant_vector(A a, ColumnPtr column_right,
+                                                   const ResultType& max_result_number,
+                                                   const ResultType& scale_diff_multiplier,
                                                    DataTypePtr res_data_type) {
         auto column_right_ptr = check_and_get_column<typename Traits::ColumnVectorB>(column_right);
         auto column_result = ColumnDecimal<ResultType>::create(
                 column_right->size(),
                 assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
         DCHECK(column_right_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_right->size(), 0);
             constant_vector(a, column_right_ptr->get_data().data(),
                             column_result->get_data().data(), null_map->get_data(),
                             column_right->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             constant_vector(a, column_right_ptr->get_data().data(),
-                            column_result->get_data().data(), column_right->size());
+                            column_result->get_data().data(), column_right->size(),
+                            max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_vector_vector(ColumnPtr column_left, ColumnPtr column_right,
+                                                 const ResultType& max_result_number,
+                                                 const ResultType& scale_diff_multiplier,
                                                  DataTypePtr res_data_type) {
         auto column_left_ptr = check_and_get_column<typename Traits::ColumnVectorA>(column_left);
         auto column_right_ptr = check_and_get_column<typename Traits::ColumnVectorB>(column_right);
 
-        auto column_result = ColumnDecimal<ResultType>::create(
-                column_left->size(),
-                assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
+        const auto& type_result = assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type);
+        auto column_result =
+                ColumnDecimal<ResultType>::create(column_left->size(), type_result.get_scale());
         DCHECK(column_left_ptr != nullptr && column_right_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_result->size(), 0);
             vector_vector(column_left_ptr->get_data().data(), column_right_ptr->get_data().data(),
                           column_result->get_data().data(), null_map->get_data(),
                           column_left->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             vector_vector(column_left_ptr->get_data().data(), column_right_ptr->get_data().data(),
-                          column_result->get_data().data(), column_left->size());
+                          column_result->get_data().data(), column_left->size(), max_result_number,
+                          scale_diff_multiplier);
             return column_result;
         }
     }
 
 private:
     /// there's implicit type conversion here
-    static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b) {
+    template <bool need_adjust_scale>
+    static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,

Review Comment:
   warning: function 'apply' has cognitive complexity of 61 (threshold 50) [readability-function-cognitive-complexity]
   ```cpp
       static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,
                                             ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/functions/function_binary_arithmetic.h:519:** +1, including nesting penalty of 0, nesting level increased to 1
   ```cpp
           if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:519:** +1
   ```cpp
           if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
                                        ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:523:** +1, nesting level increased to 1
   ```cpp
           } else {
             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:525:** +2, including nesting penalty of 1, nesting level increased to 2
   ```cpp
               if constexpr (OpTraits::can_overflow && check_overflow) {
               ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:527:** +3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if (UNLIKELY(Op::template apply<NativeResultType>(a, b, res))) {
                   ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:528:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (OpTraits::is_plus_minus) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:533:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (std::is_same_v<NativeResultType, __int128>) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:535:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:536:** +6, including nesting penalty of 5, nesting level increased to 6
   ```cpp
                               if (res256 > 0) {
                               ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:540:** +1, nesting level increased to 6
   ```cpp
                               } else {
                                 ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:546:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (res256 > wide::Int256(max_result_number.value) ||
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:546:** +1
   ```cpp
                           if (res256 > wide::Int256(max_result_number.value) ||
                                                                              ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:550:** +1, nesting level increased to 5
   ```cpp
                           } else {
                             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:553:** +1, nesting level increased to 4
   ```cpp
                       } else {
                         ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:557:** +1, nesting level increased to 3
   ```cpp
                   } else {
                     ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:559:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:560:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (res >= 0) {
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:563:** +1, nesting level increased to 5
   ```cpp
                           } else {
                             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:568:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (res > max_result_number.value || res < -max_result_number.value) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:568:** +1
   ```cpp
                       if (res > max_result_number.value || res < -max_result_number.value) {
                                                         ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:574:** +1, nesting level increased to 2
   ```cpp
               } else {
                 ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:576:** +3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                   ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:577:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (res >= 0) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:579:** +1, nesting level increased to 4
   ```cpp
                       } else {
                         ^
   ```
   
   </details>
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "Gabriel39 (via GitHub)" <gi...@apache.org>.
Gabriel39 commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1413441824


##########
be/src/common/exception.h:
##########
@@ -120,4 +120,4 @@ inline const std::string& Exception::to_string() const {
             }                                                                                    \
             return Status::Error<false>(e.code(), e.to_string());                                \
         }                                                                                        \
-    } while (0)
+    } while (0)

Review Comment:
   Add an empty line



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1414168816


##########
be/src/vec/functions/function_binary_arithmetic.h:
##########
@@ -364,121 +400,188 @@ struct DecimalBinaryOperation {
         }
     }
 
-    static ColumnPtr adapt_decimal_constant_constant(A a, B b, DataTypePtr res_data_type) {
+public:
+    static ColumnPtr adapt_decimal_constant_constant(A a, B b, const ResultType& max_result_number,
+                                                     const ResultType& scale_diff_multiplier,
+                                                     DataTypePtr res_data_type) {
         auto column_result = ColumnDecimal<ResultType>::create(
                 1, assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(1, 0);
             column_result->get_element(0) = constant_constant(a, b, null_map->get_element(0));
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
-            column_result->get_element(0) = constant_constant(a, b);
+            column_result->get_element(0) =
+                    constant_constant(a, b, max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_vector_constant(ColumnPtr column_left, B b,
+                                                   const ResultType& max_result_number,
+                                                   const ResultType& scale_diff_multiplier,
                                                    DataTypePtr res_data_type) {
         auto column_left_ptr = check_and_get_column<typename Traits::ColumnVectorA>(column_left);
         auto column_result = ColumnDecimal<ResultType>::create(
                 column_left->size(),
                 assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
         DCHECK(column_left_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_left->size(), 0);
             vector_constant(column_left_ptr->get_data().data(), b, column_result->get_data().data(),
                             null_map->get_data(), column_left->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             vector_constant(column_left_ptr->get_data().data(), b, column_result->get_data().data(),
-                            column_left->size());
+                            column_left->size(), max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_constant_vector(A a, ColumnPtr column_right,
+                                                   const ResultType& max_result_number,
+                                                   const ResultType& scale_diff_multiplier,
                                                    DataTypePtr res_data_type) {
         auto column_right_ptr = check_and_get_column<typename Traits::ColumnVectorB>(column_right);
         auto column_result = ColumnDecimal<ResultType>::create(
                 column_right->size(),
                 assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
         DCHECK(column_right_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_right->size(), 0);
             constant_vector(a, column_right_ptr->get_data().data(),
                             column_result->get_data().data(), null_map->get_data(),
                             column_right->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             constant_vector(a, column_right_ptr->get_data().data(),
-                            column_result->get_data().data(), column_right->size());
+                            column_result->get_data().data(), column_right->size(),
+                            max_result_number, scale_diff_multiplier);
             return column_result;
         }
     }
 
     static ColumnPtr adapt_decimal_vector_vector(ColumnPtr column_left, ColumnPtr column_right,
+                                                 const ResultType& max_result_number,
+                                                 const ResultType& scale_diff_multiplier,
                                                  DataTypePtr res_data_type) {
         auto column_left_ptr = check_and_get_column<typename Traits::ColumnVectorA>(column_left);
         auto column_right_ptr = check_and_get_column<typename Traits::ColumnVectorB>(column_right);
 
-        auto column_result = ColumnDecimal<ResultType>::create(
-                column_left->size(),
-                assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
+        const auto& type_result = assert_cast<const DataTypeDecimal<ResultType>&>(*res_data_type);
+        auto column_result =
+                ColumnDecimal<ResultType>::create(column_left->size(), type_result.get_scale());
         DCHECK(column_left_ptr != nullptr && column_right_ptr != nullptr);
 
-        if constexpr (return_nullable_type && !is_to_null_type &&
+        if constexpr (check_overflow && !is_to_null_type &&
                       ((!OpTraits::is_multiply && !OpTraits::is_plus_minus) || IsDecimalV2<A> ||
                        IsDecimalV2<B>)) {
             LOG(FATAL) << "Invalid function type!";
             return column_result;
-        } else if constexpr (return_nullable_type || is_to_null_type) {
+        } else if constexpr (is_to_null_type) {
             auto null_map = ColumnUInt8::create(column_result->size(), 0);
             vector_vector(column_left_ptr->get_data().data(), column_right_ptr->get_data().data(),
                           column_result->get_data().data(), null_map->get_data(),
                           column_left->size());
             return ColumnNullable::create(std::move(column_result), std::move(null_map));
         } else {
             vector_vector(column_left_ptr->get_data().data(), column_right_ptr->get_data().data(),
-                          column_result->get_data().data(), column_left->size());
+                          column_result->get_data().data(), column_left->size(), max_result_number,
+                          scale_diff_multiplier);
             return column_result;
         }
     }
 
 private:
     /// there's implicit type conversion here
-    static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b) {
+    template <bool need_adjust_scale>
+    static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,

Review Comment:
   warning: function 'apply' has cognitive complexity of 61 (threshold 50) [readability-function-cognitive-complexity]
   ```cpp
       static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,
                                             ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/functions/function_binary_arithmetic.h:519:** +1, including nesting penalty of 0, nesting level increased to 1
   ```cpp
           if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:519:** +1
   ```cpp
           if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
                                        ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:523:** +1, nesting level increased to 1
   ```cpp
           } else {
             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:525:** +2, including nesting penalty of 1, nesting level increased to 2
   ```cpp
               if constexpr (OpTraits::can_overflow && check_overflow) {
               ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:527:** +3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if (UNLIKELY(Op::template apply<NativeResultType>(a, b, res))) {
                   ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:528:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (OpTraits::is_plus_minus) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:533:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (std::is_same_v<NativeResultType, __int128>) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:535:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:536:** +6, including nesting penalty of 5, nesting level increased to 6
   ```cpp
                               if (res256 > 0) {
                               ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:540:** +1, nesting level increased to 6
   ```cpp
                               } else {
                                 ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:546:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (res256 > wide::Int256(max_result_number.value) ||
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:546:** +1
   ```cpp
                           if (res256 > wide::Int256(max_result_number.value) ||
                                                                              ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:550:** +1, nesting level increased to 5
   ```cpp
                           } else {
                             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:553:** +1, nesting level increased to 4
   ```cpp
                       } else {
                         ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:557:** +1, nesting level increased to 3
   ```cpp
                   } else {
                     ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:559:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:560:** +5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (res >= 0) {
                           ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:563:** +1, nesting level increased to 5
   ```cpp
                           } else {
                             ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:568:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (res > max_result_number.value ||
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:568:** +1
   ```cpp
                       if (res > max_result_number.value ||
                                                         ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:575:** +1, nesting level increased to 2
   ```cpp
               } else {
                 ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:577:** +3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if constexpr (OpTraits::is_multiply && need_adjust_scale) {
                   ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:578:** +4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (res >= 0) {
                       ^
   ```
   **be/src/vec/functions/function_binary_arithmetic.h:580:** +1, nesting level increased to 4
   ```cpp
                       } else {
                         ^
   ```
   
   </details>
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1837694397

    run pipelinex_p0


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1410067245


##########
be/src/common/exception.h:
##########
@@ -121,3 +121,6 @@ inline const std::string& Exception::to_string() const {
             return Status::Error<false>(e.code(), e.to_string());                                \
         }                                                                                        \
     } while (0)
+
+#define THROW_ARITHMETIC_OVERFLOW_ERRROR \
+    throw Exception(ErrorCode::ARITHMETIC_OVERFLOW_ERRROR, "Arithmetic overflow")

Review Comment:
   this macro is not reasonable.
   If we define such a macro, then we may need define many many macros... each error code need a macro



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1839864195

   PR approved by at least one committer and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1837513691

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1839006431

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1839159060

   run feut


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1839864246

   PR approved by anyone and no changes requested.


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "doris-robot (via GitHub)" <gi...@apache.org>.
doris-robot commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1838109602

   (From new machine)TeamCity pipeline, clickbench performance test result:
    the sum of best hot time: 43.95 seconds
    stream load tsv:          560 seconds loaded 74807831229 Bytes, about 127 MB/s
    stream load json:         18 seconds loaded 2358488459 Bytes, about 124 MB/s
    stream load orc:          64 seconds loaded 1101869774 Bytes, about 16 MB/s
    stream load parquet:          34 seconds loaded 861443392 Bytes, about 24 MB/s
    insert into select:          29.2 seconds inserted 10000000 Rows, about 342K ops/s
    storage size: 17163974810 Bytes


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1410062338


##########
be/src/vec/common/int_exp.h:
##########
@@ -252,4 +252,187 @@ inline wide::Int256 exp10_i256(int x) {
     return values[x];
 }
 
+constexpr inline int max_i32(int digit_count) {
+    if (digit_count < 0) {
+        return 0;
+    }
+    if (digit_count > 9) {
+        return std::numeric_limits<int>::max();
+    }
+    constexpr int values[] = {0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999};
+    return values[digit_count];
+}
+
+constexpr inline int64_t max_i64(int digit_count) {
+    if (digit_count < 0) {
+        return 0;
+    }
+    if (digit_count > 18) {
+        return std::numeric_limits<int64_t>::max();
+    }
+
+    constexpr int64_t values[] = {1LL,
+                                  9LL,
+                                  99LL,
+                                  999LL,
+                                  9999LL,
+                                  99999LL,
+                                  999999LL,
+                                  9999999LL,
+                                  99999999LL,
+                                  999999999LL,
+                                  9999999999LL,
+                                  99999999999LL,
+                                  999999999999LL,
+                                  9999999999999LL,
+                                  99999999999999LL,
+                                  999999999999999LL,
+                                  9999999999999999LL,
+                                  99999999999999999LL,
+                                  999999999999999999LL};
+    return values[digit_count];
+}
+
+constexpr inline __int128 max_i128(int digit_count) {
+    DCHECK(digit_count > 0);
+    constexpr __int128 values[] = {
+            static_cast<__int128>(0LL),
+            static_cast<__int128>(9LL),
+            static_cast<__int128>(99LL),
+            static_cast<__int128>(999LL),
+            static_cast<__int128>(9999LL),
+            static_cast<__int128>(99999LL),
+            static_cast<__int128>(999999LL),
+            static_cast<__int128>(9999999LL),
+            static_cast<__int128>(99999999LL),
+            static_cast<__int128>(999999999LL),
+            static_cast<__int128>(9999999999LL),
+            static_cast<__int128>(99999999999LL),
+            static_cast<__int128>(999999999999LL),
+            static_cast<__int128>(9999999999999LL),
+            static_cast<__int128>(99999999999999LL),
+            static_cast<__int128>(999999999999999LL),
+            static_cast<__int128>(9999999999999999LL),
+            static_cast<__int128>(99999999999999999LL),
+            static_cast<__int128>(999999999999999999LL),
+            static_cast<__int128>(1000000000000000000LL) * 10LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 1000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 10000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 1000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 10000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 1000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 10000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 1000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 10000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 1000000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 10000000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 10LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 100LL - 1,
+            static_cast<__int128>(1000000000000000000LL) * 100000000000000000LL * 1000LL - 1};
+    return values[digit_count];
+}
+
+inline wide::Int256 max_i256(int digit_count) {

Review Comment:
   warning: function 'max_i256' exceeds recommended size/complexity thresholds [readability-function-size]
   ```cpp
   inline wide::Int256 max_i256(int digit_count) {
                       ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/common/int_exp.h:340:** 96 lines including whitespace and comments (threshold 80)
   ```cpp
   inline wide::Int256 max_i256(int digit_count) {
                       ^
   ```
   
   </details>
   



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1410083831


##########
be/src/vec/data_types/data_type_decimal.h:
##########
@@ -420,34 +427,63 @@ ToDataType::FieldType convert_decimals(const typename FromDataType::FieldType& v
                                                   FromFieldType, ToFieldType>>;
 
     MaxFieldType converted_value;
+    // from integer to decimal
     if (scale_to > scale_from) {
+        LOG(WARNING) << "multiply wider scale";
         converted_value =
                 DataTypeDecimal<MaxFieldType>::get_scale_multiplier(scale_to - scale_from);
-        if (common::mul_overflow(static_cast<MaxFieldType>(value).value, converted_value.value,
-                                 converted_value.value)) {
-            if (overflow_flag) {
-                *overflow_flag = 1;
+        if constexpr (multiply_may_overflow) {
+            LOG(WARNING) << "multiply may overflow";
+            if (common::mul_overflow(static_cast<MaxFieldType>(value).value, converted_value.value,
+                                     converted_value.value)) {
+                LOG(WARNING) << "multiply may overflow, multiply overflowed"; // ok
+                THROW_ARITHMETIC_OVERFLOW_ERRROR;
+            } else {
+                if constexpr (narrow_integral) {
+                    LOG(WARNING) << "multiply may overflow, narrow integer"; // ok
+                    if (UNLIKELY(converted_value.value > max_result.value ||
+                                 converted_value.value < min_result.value)) {
+                        LOG(WARNING) << "multiply may overflow, res overflow"; // ok
+                        THROW_ARITHMETIC_OVERFLOW_ERRROR;
+                    }
+                }
             }
-            return converted_value < MaxFieldType() ? type_limit<ToFieldType>::min()
-                                                    : type_limit<ToFieldType>::max();
+        } else {
+            LOG(WARNING) << "multiply CAN'T overflow"; // ok
+            converted_value *= static_cast<MaxFieldType>(value).value;
+            if constexpr (narrow_integral) {
+                LOG(WARNING) << "multiply CAN'T overflow, narrow integer"; // ok
+                if (UNLIKELY(converted_value.value > max_result.value ||
+                             converted_value.value < min_result.value)) {
+                    LOG(WARNING) << "multiply CAN'T overflow, narrow integral"; // ok
+                    THROW_ARITHMETIC_OVERFLOW_ERRROR;
+                } // ok
+            }     // ok
         }
     } else {
+        // from decimal to integer
+        LOG(WARNING) << "multiply narrow scale"; // ok
         converted_value =
                 static_cast<MaxFieldType>(value) /
                 DataTypeDecimal<MaxFieldType>::get_scale_multiplier(scale_from - scale_to);
-    }
-
-    if constexpr (sizeof(FromFieldType) > sizeof(ToFieldType)) {
-        if (converted_value < FromFieldType(type_limit<ToFieldType>::min())) {
-            if (overflow_flag) {
-                *overflow_flag = 1;
+        if (value >= FromFieldType(0)) {
+            if constexpr (narrow_integral) {
+                LOG(WARNING) << "multiply narrow scale, positive, narrow integral"; // ok
+                if (UNLIKELY(converted_value.value > max_result.value)) {
+                    THROW_ARITHMETIC_OVERFLOW_ERRROR; // ok
+                }                                     // ok
+            } else {
+                LOG(WARNING) << "multiply narrow scale, positive, NOT narrow integral";
             }
-            return type_limit<ToFieldType>::min();
-        } else if (converted_value > FromFieldType(type_limit<ToFieldType>::max())) {
-            if (overflow_flag) {
-                *overflow_flag = 1;
+        } else {
+            if constexpr (narrow_integral) {
+                LOG(WARNING) << "multiply narrow scale, negative, narrow integral";
+                if (UNLIKELY(converted_value.value < min_result.value)) {
+                    THROW_ARITHMETIC_OVERFLOW_ERRROR;

Review Comment:
   throw exception  is better than  macro



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1410073924


##########
be/src/runtime/type_limit.h:
##########
@@ -108,4 +108,31 @@ struct type_limit<DateV2Value<DateTimeV2ValueType>> {
     }
 };
 
+template <typename T>
+constexpr vectorized::UInt32 get_number_max_digits() {
+    if constexpr (std::is_same_v<T, vectorized::UInt8> || std::is_same_v<T, vectorized::Int8>) {

Review Comment:
   add some comment



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1834070279

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1837940834

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1837962897

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "yiguolei (via GitHub)" <gi...@apache.org>.
yiguolei merged PR #27787:
URL: https://github.com/apache/doris/pull/27787


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [improvement](decimal) use new way for decimal arithmetic precision promotion [doris]

Posted by "jacktengg (via GitHub)" <gi...@apache.org>.
jacktengg commented on PR #27787:
URL: https://github.com/apache/doris/pull/27787#issuecomment-1838998227

   run buildall


-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org