This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new fb1b424195e fix](decimal) fix Arithmetic Overflow error of converting
string to decimal #32246 (#32247)
fb1b424195e is described below
commit fb1b424195ef1eeb465c98613dbb54c7be40c57f
Author: TengJianPing <[email protected]>
AuthorDate: Tue Mar 19 19:24:42 2024 +0800
fix](decimal) fix Arithmetic Overflow error of converting string to decimal
#32246 (#32247)
---
be/src/vec/data_types/data_type_decimal.cpp | 2 +-
.../data/datatype_p0/decimalv3/test_load.out | 28 +++++++++++
.../suites/datatype_p0/decimalv3/test_load.groovy | 55 ++++++++++++++++++++++
3 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/be/src/vec/data_types/data_type_decimal.cpp
b/be/src/vec/data_types/data_type_decimal.cpp
index 6d0e694f4ab..23c4f2baeb1 100644
--- a/be/src/vec/data_types/data_type_decimal.cpp
+++ b/be/src/vec/data_types/data_type_decimal.cpp
@@ -162,7 +162,7 @@ bool DataTypeDecimal<T>::parse_from_string(const
std::string& str, T* res) const
StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
*res =
StringParser::string_to_decimal<DataTypeDecimalSerDe<T>::get_primitive_type(),
__int128>(
str.c_str(), str.size(), precision, scale, &result);
- return result == StringParser::PARSE_SUCCESS;
+ return result == StringParser::PARSE_SUCCESS || result ==
StringParser::PARSE_UNDERFLOW;
}
DataTypePtr create_decimal(UInt64 precision_value, UInt64 scale_value, bool
use_v2) {
diff --git a/regression-test/data/datatype_p0/decimalv3/test_load.out
b/regression-test/data/datatype_p0/decimalv3/test_load.out
index 6907d61a12a..663c786ea8e 100644
--- a/regression-test/data/datatype_p0/decimalv3/test_load.out
+++ b/regression-test/data/datatype_p0/decimalv3/test_load.out
@@ -8,3 +8,31 @@
-99999999999999999999999999999999.999999 4.000000
99999999999999999999999999999999.999999 3.000000
+-- !decimalv3_underflow1 --
+1.00100 2.00200
+1.00200 0.00000
+1.00300 0.10000
+1.00400 0.10004
+1.00500 0.10005
+
+-- !decimalv3_underflow2 --
+1.00100 0.00000
+1.00200 0.00000
+1.00300 0.10000
+1.00400 0.10004
+1.00500 0.10005
+
+-- !decimalv3_underflow3 --
+1.00100 2.00200
+1.00200 0.00000
+1.00300 0.10000
+1.00400 0.10004
+1.00500 0.10005
+
+-- !decimalv3_underflow4 --
+1.00100 0.00000
+1.00200 0.00000
+1.00300 0.10000
+1.00400 0.10004
+1.00500 0.10005
+
diff --git a/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
b/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
index 74de23bcf9c..1c0c95e5325 100644
--- a/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
+++ b/regression-test/suites/datatype_p0/decimalv3/test_load.groovy
@@ -104,4 +104,59 @@ suite("test_load") {
exception "error"
}
qt_decimalv3_insert "select * from test_decimalv3_insert order by 1, 2;"
+
+ // fix
+ sql """ set enable_nereids_dml=true; """
+ sql """
+ drop TABLE if exists test_sys_update_basic_test_update_decimal_tb;
+ """
+ sql """
+ CREATE TABLE test_sys_update_basic_test_update_decimal_tb (
+ k1 DECIMAL(10, 5) NULL,
+ v1 DECIMAL(10, 5) NULL
+ ) UNIQUE KEY(k1) DISTRIBUTED BY HASH(k1) BUCKETS 5 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );
+ """
+ sql """
+ insert into test_sys_update_basic_test_update_decimal_tb values
+ (1.001, 2.002), (1.002, 0.00000002), (1.003, 0.100000001), (1.004,
0.100044001), (1.005, 0.100045001);
+ """
+ qt_decimalv3_underflow1 """
+ select * from test_sys_update_basic_test_update_decimal_tb order by 1,
2;
+ """
+ sql """
+ UPDATE test_sys_update_basic_test_update_decimal_tb SET
v1="0.00000001" WHERE k1 = 1.001;
+ """
+ qt_decimalv3_underflow2 """
+ select * from test_sys_update_basic_test_update_decimal_tb order by 1,
2;
+ """
+
+ sql """ set enable_nereids_dml=false; """
+ sql """
+ drop TABLE if exists test_sys_update_basic_test_update_decimal_tb;
+ """
+ sql """
+ CREATE TABLE test_sys_update_basic_test_update_decimal_tb (
+ k1 DECIMAL(10, 5) NULL,
+ v1 DECIMAL(10, 5) NULL
+ ) UNIQUE KEY(k1) DISTRIBUTED BY HASH(k1) BUCKETS 5 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );
+ """
+ sql """
+ insert into test_sys_update_basic_test_update_decimal_tb values
+ (1.001, 2.002), (1.002, 0.00000002), (1.003, 0.100000001), (1.004,
0.100044001), (1.005, 0.100045001);
+ """
+ qt_decimalv3_underflow3 """
+ select * from test_sys_update_basic_test_update_decimal_tb order by 1,
2;
+ """
+ // need to use "1.001"(quoted) because non-nereids dml seems treat 1.001
as double,
+ // which will cause wrong result of decimal comparision
+ sql """
+ UPDATE test_sys_update_basic_test_update_decimal_tb SET
v1="0.00000001" WHERE k1 = "1.001";
+ """
+ qt_decimalv3_underflow4 """
+ select * from test_sys_update_basic_test_update_decimal_tb order by 1,
2;
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]