Skip to content

Commit 5cbfc0a

Browse files
Mryangedataroaring
authored andcommitted
[fix](function) fix error return type in mod(float32,BigInt) (#39358)
## Proposed changes ``` CREATE TABLE testdb ( K1 BIGINT, K2 FLOAT ) properties("replication_num" = "1"); insert into testdb values(1,1.1); select mod(k1,k2) from testdb; mysql [test10]>select mod(k1,k2) from testdb; ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INTERNAL_ERROR]Function mod get failed, expr is VectorizedFnCall[mod](arguments=K1, K2,return=Nullable(Float32)) and return type is Nullable(Float32). ``` <!--Describe your changes.-->
1 parent b27ce2e commit 5cbfc0a

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

be/src/vec/data_types/number_traits.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,22 @@ struct ResultOfIntegerDivision {
183183
*/
184184
template <typename A, typename B>
185185
struct ResultOfModulo {
186-
using Type = typename Construct<std::is_signed_v<A> || std::is_signed_v<B>,
187-
std::is_floating_point_v<A> || std::is_floating_point_v<B>,
188-
max(sizeof(A), sizeof(B))>::Type;
186+
constexpr static auto has_float = std::is_floating_point_v<A> || std::is_floating_point_v<B>;
187+
consteval static auto result_size() {
188+
if constexpr (!has_float) {
189+
return max(sizeof(A), sizeof(B));
190+
}
191+
size_t max_float_size = 0;
192+
if constexpr (std::is_floating_point_v<A>) {
193+
max_float_size = max(max_float_size, sizeof(A));
194+
}
195+
if constexpr (std::is_floating_point_v<B>) {
196+
max_float_size = max(max_float_size, sizeof(B));
197+
}
198+
return max_float_size;
199+
}
200+
using Type = typename Construct<std::is_signed_v<A> || std::is_signed_v<B>, has_float,
201+
result_size()>::Type;
189202
};
190203

191204
template <typename A>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !sql --
3+
1.0
4+

regression-test/suites/nereids_p0/sql_functions/test_arith_functions.groovy

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ suite("test_arith_functions") {
3232
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'
3333
result([[11022916880, 11902L]])
3434
}
35+
36+
sql """
37+
CREATE TABLE testmoddb (
38+
K1 BIGINT,
39+
K2 FLOAT
40+
) properties("replication_num" = "1");
41+
42+
"""
43+
44+
sql """
45+
insert into testmoddb values(1,1.1);
46+
"""
47+
48+
qt_sql """ select mod(k1,k2) from testmoddb; """
49+
3550
// test {
3651
// sql 'select int_divide(k1, k2), bitand(k2, k3), bitor(k3, k4), bitxor(k4, k3), bitnot(k4) from test order by k1'
3752
// }

0 commit comments

Comments
 (0)