This is an automated email from the ASF dual-hosted git repository. jacktengg pushed a commit to branch 2.0.10-decimal-patch in repository https://gitbox.apache.org/repos/asf/doris.git
commit 42dfa64a341e95d3dc16f3aa0fa38e3fd79724f7 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Fri May 24 11:27:05 2024 +0800 [fix](decimal) Fix wrong result produced by decimal128 multiply (#34825) (#35253) --- be/src/vec/common/arithmetic_overflow.h | 2 +- .../datatype_p0/decimalv3/test_decimalv3_overflow.out | 3 +++ .../datatype_p0/decimalv3/test_decimalv3_overflow.groovy | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/be/src/vec/common/arithmetic_overflow.h b/be/src/vec/common/arithmetic_overflow.h index b8dc5a5fab3..39714ce45d4 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 <> inline bool mul_overflow(wide::Int256 x, wide::Int256 y, wide::Int256& res) { 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 ddcadbfbf2e..389527cc3fe 100644 --- a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out +++ b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out @@ -73,3 +73,6 @@ 1.1 1.111120000000000000000000000000000000 2.21 123456789012345678901234567890123456.7 1.234567890123456789012345678901234567 123456789012345678901234567890123457.93 +-- !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 fc9d264a05c..4add26e590a 100644 --- a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy +++ b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy @@ -566,4 +566,20 @@ suite("test_decimalv3_overflow") { >>> len('57896044618658097711785492504343953926634992332820282019728792003956564819967') 77 */ + + 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org