From a434a49f71e7ecdcb4ffa760a09f09bb94a49c14 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 23 May 2023 18:24:31 +0800 Subject: [PATCH] [Bug](decimal) fix `mod` function (#19925) Bug: select id, kdcml * ktint, kdcml / ktint, kdcml % ktint from expr_test order by id; +------+-------------------+-------------------+-----------------------+ | id | kdcml * ktint | kdcml / ktint | kdcml % ktint | +------+-------------------+-------------------+-----------------------+ | NULL | NULL | NULL | NULL | | 1 | 24.395 | 24.395 | -4702111234474983.74 | | 2 | 68.968 | 17.242 | -4702111234474983.74 | | 3 | 146.268 | 16.252 | -4702111234474983.74 | | 4 | 275.772 | 17.235 | -4702111234474983.74 | | 5 | 487.470 | 19.498 | -4702111234474983.74 | | 6 | 827.244 | 22.979 | -4702111234474983.74 | | 7 | 1364.860 | 27.854 | -4702111234474983.74 | | 8 | 2205.928 | 34.467 | -4702111234474983.74 | | 9 | 3509.595 | 43.328 | -4702111234474983.74 | | 10 | 5514.790 | 55.147 | -4702111234474983.74 | | 11 | 8578.988 | 70.900 | -4702111234474983.74 | | 12 | 13235.484 | 91.913 | -4702111234474983.74 | | 13 | 24.395 | 24.395 | -4702111234474983.74 | | 14 | 68.968 | 17.242 | -4702111234474983.74 | | 15 | 146.268 | 16.252 | -4702111234474983.74 | | 16 | 275.772 | 17.235 | -4702111234474983.74 | | 17 | 487.470 | 19.498 | -4702111234474983.74 | | 18 | 827.244 | 22.979 | -4702111234474983.74 | | 19 | 1364.860 | 27.854 | -4702111234474983.74 | | 20 | 2205.928 | 34.467 | -4702111234474983.74 | | 21 | 3509.595 | 43.328 | -4702111234474983.74 | | 22 | 5514.790 | 55.147 | -4702111234474983.74 | | 23 | 8578.988 | 70.900 | -4702111234474983.74 | | 24 | 13235.484 | 91.913 | -4702111234474983.74 | --- .../functions/function_binary_arithmetic.h | 4 ++++ .../decimalv3/test_arithmetic_expressions.out | 6 +++++ .../test_arithmetic_expressions.groovy | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index e95a6adc1f..8db58b072f 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -262,6 +262,10 @@ struct DecimalBinaryOperation { for (size_t i = 0; i < size; ++i) { null_map[i] = apply_op_safely(a[i], b[i], c[i].value); } + } else { + for (size_t i = 0; i < size; ++i) { + c[i] = apply(a[i], b[i], null_map[i]); + } } } diff --git a/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out index 7f29407e10..381a4612bb 100644 --- a/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out +++ b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out @@ -53,3 +53,9 @@ 3 724.291976000 724.291976000 4 688.890183155 688.890183155 +-- !select -- +92594283.129196000 1 0.129196000 0.129196000 +107684988.257976000 3 0.257976000 0.257976000 +76891560.464178000 5 0.464178000 0.464178000 +277170831.851350000 7 0.851350000 0.851350000 + diff --git a/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy index b077e4c362..1d7fbb39b0 100644 --- a/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy +++ b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy @@ -87,4 +87,26 @@ suite("test_arithmetic_expressions") { qt_select """ select id, fz/fm as dec,fzv3/fm as decv3 from ${table2} ORDER BY id; """ sql "drop table if exists ${table2}" + + def table3 = "test_mod_expressions" + + sql "drop table if exists ${table3}" + sql """ create table ${table3} ( + id smallint, + v1 decimalv3(27,9), + v2 decimalv3(9,0), + v3 int ) + DISTRIBUTED BY HASH(`id`) BUCKETS auto + PROPERTIES + ( + "replication_num" = "1" + ); """ + + sql """ insert into ${table3} values (1,92594283.129196000,1,1); """ + sql """ insert into ${table3} values (2,107684988.257976000,3,3); """ + sql """ insert into ${table3} values (3,76891560.464178000,5,5); """ + sql """ insert into ${table3} values (4,277170831.851350000,7,7); """ + + qt_select """ select v1, v2, v1 % v2, v1 % v3 from ${table3} ORDER BY id; """ + sql "drop table if exists ${table3}" }