Skip to content

Commit

Permalink
select compare predicate OK
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktengg committed Oct 7, 2023
1 parent 8f58458 commit 0b2e400
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
5 changes: 5 additions & 0 deletions be/src/vec/core/call_on_type_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bool call_on_basic_type(TypeIndex number, F&& f) {
return f(TypePair<T, Decimal128>());
case TypeIndex::Decimal128I:
return f(TypePair<T, Decimal128I>());
case TypeIndex::Decimal256:
return f(TypePair<T, Decimal256>());
default:
break;
}
Expand Down Expand Up @@ -143,6 +145,9 @@ bool call_on_basic_types(TypeIndex type_num1, TypeIndex type_num2, F&& f) {
case TypeIndex::Decimal128I:
return call_on_basic_type<Decimal128I, _int, _float, _decimal, _datetime>(
type_num2, std::forward<F>(f));
case TypeIndex::Decimal256:
return call_on_basic_type<Decimal256, _int, _float, _decimal, _datetime>(
type_num2, std::forward<F>(f));
default:
break;
}
Expand Down
27 changes: 19 additions & 8 deletions be/src/vec/core/decimal_comparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "vec/core/accurate_comparison.h"
#include "vec/core/block.h"
#include "vec/core/call_on_type_index.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type_decimal.h"
#include "vec/functions/function_helpers.h" /// todo core should not depend on function"

Expand Down Expand Up @@ -153,12 +154,12 @@ class DecimalComparison {
using Type = std::conditional_t<sizeof(T) >= sizeof(U), T, U>;
auto type_ptr = decimal_result_type(*decimal0, *decimal1, false, false, false);
const DataTypeDecimal<Type>* result_type = check_decimal<Type>(*type_ptr);
shift.a = result_type->scale_factor_for(*decimal0, false);
shift.b = result_type->scale_factor_for(*decimal1, false);
shift.a = result_type->scale_factor_for(*decimal0, false).value;
shift.b = result_type->scale_factor_for(*decimal1, false).value;
} else if (decimal0) {
shift.b = decimal0->get_scale_multiplier();
shift.b = decimal0->get_scale_multiplier().value;
} else if (decimal1) {
shift.a = decimal1->get_scale_multiplier();
shift.a = decimal1->get_scale_multiplier().value;
}

return shift;
Expand All @@ -169,7 +170,7 @@ class DecimalComparison {
static Shift getScales(const DataTypePtr& left_type, const DataTypePtr&) {
Shift shift;
const DataTypeDecimal<T>* decimal0 = check_decimal<T>(*left_type);
if (decimal0) shift.b = decimal0->get_scale_multiplier();
if (decimal0) shift.b = decimal0->get_scale_multiplier().value;
return shift;
}

Expand All @@ -178,7 +179,7 @@ class DecimalComparison {
static Shift getScales(const DataTypePtr&, const DataTypePtr& right_type) {
Shift shift;
const DataTypeDecimal<U>* decimal1 = check_decimal<U>(*right_type);
if (decimal1) shift.a = decimal1->get_scale_multiplier();
if (decimal1) shift.a = decimal1->get_scale_multiplier().value;
return shift;
}

Expand Down Expand Up @@ -238,8 +239,18 @@ class DecimalComparison {

template <bool scale_left, bool scale_right>
static NO_INLINE UInt8 apply(A a, B b, CompareInt scale [[maybe_unused]]) {
CompareInt x = a;
CompareInt y = b;
CompareInt x;
CompareInt y;
if constexpr (IsDecimalNumber<A>) {
x = a.value;
} else {
x = a;
}
if constexpr (IsDecimalNumber<B>) {
y = b.value;
} else {
y = b;
}

if constexpr (_check_overflow) {
bool overflow = false;
Expand Down
8 changes: 8 additions & 0 deletions be/src/vec/core/wide_integer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ struct integer<Bits, Signed>::_impl {
for (unsigned i = 1; i < item_count; ++i) self.items[little(i)] = 0;
}

template <>
constexpr static void wide_integer_from_builtin<__int128>(integer<Bits, Signed>& self,
__int128 rhs) noexcept {
self.items[little(0)] = rhs;
self.items[little(1)] = rhs >> 64;
for (unsigned i = 2; i < item_count; ++i) self.items[little(i)] = 0;
}

template <typename TupleLike, size_t i = 0>
constexpr static void wide_integer_from_tuple_like(integer<Bits, Signed>& self,
const TupleLike& tuple) noexcept {
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/data_types/data_type_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ ToDataType::FieldType convert_from_decimal(const typename FromDataType::FieldTyp
if constexpr (IsDecimalV2<FromFieldType>) {
return binary_cast<int128_t, DecimalV2Value>(value);
} else {
return static_cast<ToFieldType>(value) / FromDataType::get_scale_multiplier(scale);
return static_cast<ToFieldType>(value.value) / FromDataType::get_scale_multiplier(scale).value;
}
} else {
FromFieldType converted_value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ public static ImmutableSetMultimap<PrimitiveType, PrimitiveType> getImplicitCast
builder.put(DECIMAL128, VARCHAR);
builder.put(DECIMAL128, STRING);

builder.put(DECIMAL256, BOOLEAN);
builder.put(DECIMAL256, TINYINT);
builder.put(DECIMAL256, SMALLINT);
builder.put(DECIMAL256, INT);
builder.put(DECIMAL256, BIGINT);
builder.put(DECIMAL256, LARGEINT);
builder.put(DECIMAL256, FLOAT);
builder.put(DECIMAL256, DOUBLE);
builder.put(DECIMAL256, DECIMALV2);
builder.put(DECIMAL256, DECIMAL32);
builder.put(DECIMAL256, DECIMAL64);
builder.put(DECIMAL256, DECIMAL128);
builder.put(DECIMAL256, DECIMAL256);
builder.put(DECIMAL256, VARCHAR);
builder.put(DECIMAL256, STRING);

// JSONB
builder.put(JSONB, BOOLEAN);
builder.put(JSONB, TINYINT);
Expand Down

0 comments on commit 0b2e400

Please sign in to comment.