From 0b2e4001fa6f15389565d0d810b22fb0fe6493c5 Mon Sep 17 00:00:00 2001 From: jacktengg <18241664+jacktengg@users.noreply.github.com> Date: Sat, 7 Oct 2023 17:12:48 +0800 Subject: [PATCH] select compare predicate OK --- be/src/vec/core/call_on_type_index.h | 5 ++++ be/src/vec/core/decimal_comparison.h | 27 +++++++++++++------ be/src/vec/core/wide_integer_impl.h | 8 ++++++ be/src/vec/data_types/data_type_decimal.h | 2 +- .../apache/doris/catalog/PrimitiveType.java | 16 +++++++++++ 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/be/src/vec/core/call_on_type_index.h b/be/src/vec/core/call_on_type_index.h index 283f7aeb078c64..d7da0c6aa18e6c 100644 --- a/be/src/vec/core/call_on_type_index.h +++ b/be/src/vec/core/call_on_type_index.h @@ -72,6 +72,8 @@ bool call_on_basic_type(TypeIndex number, F&& f) { return f(TypePair()); case TypeIndex::Decimal128I: return f(TypePair()); + case TypeIndex::Decimal256: + return f(TypePair()); default: break; } @@ -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( type_num2, std::forward(f)); + case TypeIndex::Decimal256: + return call_on_basic_type( + type_num2, std::forward(f)); default: break; } diff --git a/be/src/vec/core/decimal_comparison.h b/be/src/vec/core/decimal_comparison.h index d7eb5cf9d19cb5..dd19731d588788 100644 --- a/be/src/vec/core/decimal_comparison.h +++ b/be/src/vec/core/decimal_comparison.h @@ -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" @@ -153,12 +154,12 @@ class DecimalComparison { using Type = std::conditional_t= sizeof(U), T, U>; auto type_ptr = decimal_result_type(*decimal0, *decimal1, false, false, false); const DataTypeDecimal* result_type = check_decimal(*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; @@ -169,7 +170,7 @@ class DecimalComparison { static Shift getScales(const DataTypePtr& left_type, const DataTypePtr&) { Shift shift; const DataTypeDecimal* decimal0 = check_decimal(*left_type); - if (decimal0) shift.b = decimal0->get_scale_multiplier(); + if (decimal0) shift.b = decimal0->get_scale_multiplier().value; return shift; } @@ -178,7 +179,7 @@ class DecimalComparison { static Shift getScales(const DataTypePtr&, const DataTypePtr& right_type) { Shift shift; const DataTypeDecimal* decimal1 = check_decimal(*right_type); - if (decimal1) shift.a = decimal1->get_scale_multiplier(); + if (decimal1) shift.a = decimal1->get_scale_multiplier().value; return shift; } @@ -238,8 +239,18 @@ class DecimalComparison { template 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) { + x = a.value; + } else { + x = a; + } + if constexpr (IsDecimalNumber) { + y = b.value; + } else { + y = b; + } if constexpr (_check_overflow) { bool overflow = false; diff --git a/be/src/vec/core/wide_integer_impl.h b/be/src/vec/core/wide_integer_impl.h index b3f1198d89ed50..6ff584afa28861 100644 --- a/be/src/vec/core/wide_integer_impl.h +++ b/be/src/vec/core/wide_integer_impl.h @@ -245,6 +245,14 @@ struct integer::_impl { for (unsigned i = 1; i < item_count; ++i) self.items[little(i)] = 0; } + template <> + constexpr static void wide_integer_from_builtin<__int128>(integer& 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 constexpr static void wide_integer_from_tuple_like(integer& self, const TupleLike& tuple) noexcept { diff --git a/be/src/vec/data_types/data_type_decimal.h b/be/src/vec/data_types/data_type_decimal.h index 0034655886309f..3dde8addaceef3 100644 --- a/be/src/vec/data_types/data_type_decimal.h +++ b/be/src/vec/data_types/data_type_decimal.h @@ -536,7 +536,7 @@ ToDataType::FieldType convert_from_decimal(const typename FromDataType::FieldTyp if constexpr (IsDecimalV2) { return binary_cast(value); } else { - return static_cast(value) / FromDataType::get_scale_multiplier(scale); + return static_cast(value.value) / FromDataType::get_scale_multiplier(scale).value; } } else { FromFieldType converted_value = diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/PrimitiveType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/PrimitiveType.java index a5d6145a8fc48f..171d242ab6599b 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/PrimitiveType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/PrimitiveType.java @@ -527,6 +527,22 @@ public static ImmutableSetMultimap 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);