This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 963b78c500b [fix](decimal) Fix wrong result produced by decimal128
multiply (#34825)
963b78c500b is described below
commit 963b78c500b3067219bac54bb4e0ae2e0d245487
Author: Gabriel <[email protected]>
AuthorDate: Tue May 14 23:33:21 2024 +0800
[fix](decimal) Fix wrong result produced by decimal128 multiply (#34825)
* [fix](decimal) Fix wrong result produced by decimal128 multiply
* update
---
be/src/vec/common/arithmetic_overflow.h | 2 +-
.../datatype_p0/decimalv3/test_decimalv3_overflow.out | 3 +++
.../datatype_p0/decimalv3/test_decimalv3_overflow.groovy | 15 +++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/be/src/vec/common/arithmetic_overflow.h
b/be/src/vec/common/arithmetic_overflow.h
index caccf7b9c28..6a586a8f689 100644
--- a/be/src/vec/common/arithmetic_overflow.h
+++ b/be/src/vec/common/arithmetic_overflow.h
@@ -123,7 +123,7 @@ inline bool mul_overflow(__int128 x, __int128 y, __int128&
res) {
unsigned __int128 a = (x > 0) ? x : -x;
unsigned __int128 b = (y > 0) ? y : -y;
- return (a * b) / b != a;
+ return ((a * b) / b != a) || (x > 0 && y > 0 && res < 0) || (x < 0 && y <
0 && res < 0);
}
template <>
diff --git
a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out
b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out
index 06cf127c683..9442c908b06 100644
--- a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out
+++ b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out
@@ -95,3 +95,6 @@
-- !except2 --
999999999999999999.9
+-- !sql --
+62324.000000000000000000 0.002730000000000000 170.144520
+
diff --git
a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy
b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy
index 384ba1fd8c3..b5cfe16a77f 100644
---
a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy
+++
b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy
@@ -634,4 +634,19 @@ suite("test_decimalv3_overflow") {
qt_except2 """
select * from (select * from test_decimalv3_tb2 except select * from
test_decimalv3_tb1) t order by 1;
"""
+ sql """ CREATE TABLE IF NOT EXISTS test4
+ (
+ id BIGINT NOT NULL COMMENT '',
+ price DECIMAL(38, 18) NOT NULL COMMENT '',
+ size DECIMAL(38, 18) NOT NULL COMMENT ''
+ ) UNIQUE KEY(`id`)
+ DISTRIBUTED BY HASH(`id`) BUCKETS 10
+ PROPERTIES(
+ "replication_num"="1",
+ "compaction_policy" = "time_series",
+ "enable_unique_key_merge_on_write" = "true"
+ ); """
+ sql """ insert into test4 values(1, 62324, 0.00273) """
+ qt_sql """ select price, size, price * size from test4; """
+ sql "drop table if exists test4"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]