diff --git a/be/src/vec/data_types/number_traits.h b/be/src/vec/data_types/number_traits.h index 4f97a2667664d7..76944461c75753 100644 --- a/be/src/vec/data_types/number_traits.h +++ b/be/src/vec/data_types/number_traits.h @@ -183,9 +183,22 @@ struct ResultOfIntegerDivision { */ template struct ResultOfModulo { - using Type = typename Construct || std::is_signed_v, - std::is_floating_point_v || std::is_floating_point_v, - max(sizeof(A), sizeof(B))>::Type; + constexpr static auto has_float = std::is_floating_point_v || std::is_floating_point_v; + consteval static auto result_size() { + if constexpr (!has_float) { + return max(sizeof(A), sizeof(B)); + } + size_t max_float_size = 0; + if constexpr (std::is_floating_point_v) { + max_float_size = max(max_float_size, sizeof(A)); + } + if constexpr (std::is_floating_point_v) { + max_float_size = max(max_float_size, sizeof(B)); + } + return max_float_size; + } + using Type = typename Construct || std::is_signed_v, has_float, + result_size()>::Type; }; template diff --git a/regression-test/data/nereids_p0/sql_functions/test_arith_functions.out b/regression-test/data/nereids_p0/sql_functions/test_arith_functions.out new file mode 100644 index 00000000000000..4f72ab0554ca2d --- /dev/null +++ b/regression-test/data/nereids_p0/sql_functions/test_arith_functions.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +1.0 + diff --git a/regression-test/suites/nereids_p0/sql_functions/test_arith_functions.groovy b/regression-test/suites/nereids_p0/sql_functions/test_arith_functions.groovy index 2778d0f3599f14..cb68fb3846b304 100644 --- a/regression-test/suites/nereids_p0/sql_functions/test_arith_functions.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/test_arith_functions.groovy @@ -32,6 +32,21 @@ suite("test_arith_functions") { sql 'select add(k1, k2) + subtract(k2, k3) + multiply(k3, k4), cast(divide(k4, k3) + mod(k4, k3) as bigint) from test order by k1 limit 1' result([[11022916880, 11902L]]) } + + sql """ + CREATE TABLE testmoddb ( + K1 BIGINT, + K2 FLOAT + ) properties("replication_num" = "1"); + + """ + + sql """ + insert into testmoddb values(1,1.1); + """ + + qt_sql """ select mod(k1,k2) from testmoddb; """ + // test { // sql 'select int_divide(k1, k2), bitand(k2, k3), bitor(k3, k4), bitxor(k4, k3), bitnot(k4) from test order by k1' // }