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

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 8440303b91f [fix](delete) Incorrect precision detection for the 
decimal type in condition.​ (#37801) (#37904)
8440303b91f is described below

commit 8440303b91f11c535ca60bcdce195d2f3221ffb1
Author: Jerry Hu <[email protected]>
AuthorDate: Tue Jul 16 19:02:02 2024 +0800

    [fix](delete) Incorrect precision detection for the decimal type in 
condition.​ (#37801) (#37904)
    
    ## Proposed changes
    
    pick #37801
    
    For precision like Decimal(7,7), the value "0.1234567" should be
    valid(the integer part is 0).
    
    ## Proposed changes
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 be/src/olap/utils.cpp                               | 13 ++++++++-----
 regression-test/data/delete_p0/test_delete.out      |  3 ++-
 regression-test/suites/delete_p0/test_delete.groovy | 16 +++++++++++++---
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/be/src/olap/utils.cpp b/be/src/olap/utils.cpp
index 019a2f606ce..aa641207b23 100644
--- a/be/src/olap/utils.cpp
+++ b/be/src/olap/utils.cpp
@@ -537,7 +537,7 @@ bool valid_signed_number<int128_t>(const std::string& 
value_str) {
 }
 
 bool valid_decimal(const std::string& value_str, const uint32_t precision, 
const uint32_t frac) {
-    const char* decimal_pattern = "-?\\d+(.\\d+)?";
+    const char* decimal_pattern = "-?(\\d+)(.\\d+)?";
     std::regex e(decimal_pattern);
     std::smatch what;
     if (!std::regex_match(value_str, what, e) || what[0].str().size() != 
value_str.size()) {
@@ -562,11 +562,14 @@ bool valid_decimal(const std::string& value_str, const 
uint32_t precision, const
         fractional_len = number_length - point_pos - 1;
     }
 
-    if (integer_len <= (precision - frac) && fractional_len <= frac) {
-        return true;
-    } else {
-        return false;
+    /// For value likes "0.xxxxxx", the integer_len should actually be 0.
+    if (integer_len == 1 && precision - frac == 0) {
+        if (what[1].str() == "0") {
+            integer_len = 0;
+        }
     }
+
+    return (integer_len <= (precision - frac) && fractional_len <= frac);
 }
 
 bool valid_datetime(const std::string& value_str, const uint32_t scale) {
diff --git a/regression-test/data/delete_p0/test_delete.out 
b/regression-test/data/delete_p0/test_delete.out
index db863bd96c2..ce683187974 100644
--- a/regression-test/data/delete_p0/test_delete.out
+++ b/regression-test/data/delete_p0/test_delete.out
@@ -146,4 +146,5 @@ ccc ccc
 43     44      46      47      135.200 g       t       2023-02-14      
2023-02-14T00:01:02     false   22240.106       rr
 
 -- !check_decimal --
-true   -1.0    10
\ No newline at end of file
+true   -1.0    10      0.7654321
+
diff --git a/regression-test/suites/delete_p0/test_delete.groovy 
b/regression-test/suites/delete_p0/test_delete.groovy
index 93bcad81d2c..94b2e1751c4 100644
--- a/regression-test/suites/delete_p0/test_delete.groovy
+++ b/regression-test/suites/delete_p0/test_delete.groovy
@@ -518,7 +518,8 @@ suite("test_delete") {
         CREATE TABLE table_decimal (
           `k1` BOOLEAN NOT NULL,
           `k2` DECIMAL(17, 1) NOT NULL,
-          `k3` INT NOT NULL
+          `k3` INT NOT NULL,
+          `k4` DECIMAL(7, 7)
         ) ENGINE=OLAP 
         DUPLICATE KEY(`k1`,`k2`,`k3`) 
         DISTRIBUTED BY HASH(`k1`,`k2`,`k3`) BUCKETS 4 
@@ -529,12 +530,21 @@ suite("test_delete") {
     """
     sql """
         insert into table_decimal values
-        (false, '-9999782574499444.2', -20),
-        (true, '-1', 10);
+        (false, '-9999782574499444.2', -20, 0.1234567),
+        (true, '-1', 10, 0.7654321);
     """
     sql """
         delete from table_decimal where k1 = false and k2 = 
'-9999782574499444.2' and k3 = '-20';
     """
+
+    sql """
+        delete from table_decimal where k4 = '0.1234567';
+    """
+
+    sql """
+        delete from table_decimal where k4 = '-0.123';
+    """
+
     qt_check_decimal """
         select * from table_decimal;
     """


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to