Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions be/src/vec/data_types/number_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,22 @@ struct ResultOfIntegerDivision {
*/
template <typename A, typename B>
struct ResultOfModulo {
using Type = typename Construct<std::is_signed_v<A> || std::is_signed_v<B>,
std::is_floating_point_v<A> || std::is_floating_point_v<B>,
max(sizeof(A), sizeof(B))>::Type;
constexpr static auto has_float = std::is_floating_point_v<A> || std::is_floating_point_v<B>;
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<A>) {
max_float_size = max(max_float_size, sizeof(A));
}
if constexpr (std::is_floating_point_v<B>) {
max_float_size = max(max_float_size, sizeof(B));
}
return max_float_size;
}
using Type = typename Construct<std::is_signed_v<A> || std::is_signed_v<B>, has_float,
result_size()>::Type;
};

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

Original file line number Diff line number Diff line change
Expand Up @@ -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'
// }
Expand Down
Loading