You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2023/04/03 07:31:00 UTC

[doris] branch master updated: [Bug](decimal) Fix string to decimal (#18282)

This is an automated email from the ASF dual-hosted git repository.

lihaopeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 368a2f7ace [Bug](decimal) Fix string to decimal (#18282)
368a2f7ace is described below

commit 368a2f7ace19e3ec854facfc5f0f278a3103ee71
Author: Gabriel <ga...@gmail.com>
AuthorDate: Mon Apr 3 15:30:48 2023 +0800

    [Bug](decimal) Fix string to decimal (#18282)
---
 be/src/util/string_parser.hpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp
index ff473bf401..5c776029da 100644
--- a/be/src/util/string_parser.hpp
+++ b/be/src/util/string_parser.hpp
@@ -647,7 +647,6 @@ T StringParser::string_to_decimal(const char* s, int len, int type_precision, in
     }
 
     // Find the number of truncated digits before adjusting the precision for an exponent.
-    int truncated_digit_count = precision - type_precision;
     if (exponent > scale) {
         // Ex: 0.1e3 (which at this point would have precision == 1 and scale == 1), the
         //     scale must be set to 0 and the value set to 100 which means a precision of 3.
@@ -679,9 +678,6 @@ T StringParser::string_to_decimal(const char* s, int len, int type_precision, in
     } else if (UNLIKELY(scale > type_scale)) {
         *result = StringParser::PARSE_UNDERFLOW;
         int shift = scale - type_scale;
-        if (UNLIKELY(truncated_digit_count > 0)) {
-            shift -= truncated_digit_count;
-        }
         if (shift > 0) {
             T divisor;
             if constexpr (std::is_same_v<T, vectorized::Int128I>) {
@@ -689,14 +685,14 @@ T StringParser::string_to_decimal(const char* s, int len, int type_precision, in
             } else {
                 divisor = get_scale_multiplier<T>(shift);
             }
-            if (LIKELY(divisor >= 0)) {
+            if (LIKELY(divisor > 0)) {
                 T remainder = value % divisor;
                 value /= divisor;
                 if ((remainder > 0 ? T(remainder) : T(-remainder)) >= (divisor >> 1)) {
                     value += 1;
                 }
             } else {
-                DCHECK(divisor == -1); // //DCHECK_EQ doesn't work with __int128.
+                DCHECK(divisor == -1 || divisor == 0); // //DCHECK_EQ doesn't work with __int128.
                 value = 0;
             }
         }


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