From 0873c85efaeac057baab4bdc257c77ab42cbad35 Mon Sep 17 00:00:00 2001 From: Kang Date: Wed, 1 Feb 2023 18:00:37 +0800 Subject: [PATCH 1/2] fix topn runtime predicate getting value bug for decimal type --- be/src/exec/olap_common.h | 2 +- be/src/runtime/runtime_predicate.h | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h index 034696de6e1a33..0000ea8a9edea3 100644 --- a/be/src/exec/olap_common.h +++ b/be/src/exec/olap_common.h @@ -45,7 +45,7 @@ std::string cast_to_string(T value, int scale) { std::stringstream ss; vectorized::write_text((int64_t)value, scale, ss); return ss.str(); - } else if constexpr (primitive_type == TYPE_DECIMAL128I) { + } else if constexpr (primitive_type == TYPE_DECIMAL128I || primitive_type == TYPE_DECIMALV2) { std::stringstream ss; vectorized::write_text((int128_t)value, scale, ss); return ss.str(); diff --git a/be/src/runtime/runtime_predicate.h b/be/src/runtime/runtime_predicate.h index 1356127268285c..3cfdc296f36ef5 100644 --- a/be/src/runtime/runtime_predicate.h +++ b/be/src/runtime/runtime_predicate.h @@ -147,30 +147,29 @@ class RuntimePredicate { } static std::string get_decimalv2_value(const Field& field) { - using ValueType = typename PrimitiveTypeTraits::CppType; - ValueType value; + // can NOT use PrimitiveTypeTraits::CppType since + // it is DecimalV2Value and Decimal128 can not convert to it implicitly + using ValueType = Decimal128::NativeType; auto v = field.get>(); - value.from_olap_decimal(v.get_value(), v.get_scale()); - int scale = v.get_scale(); - return cast_to_string(value, scale); + return cast_to_string(v.get_value(), v.get_scale()); } static std::string get_decimal32_value(const Field& field) { using ValueType = typename PrimitiveTypeTraits::CppType; - ValueType value = field.get(); - return cast_to_string(value, 0); + auto v = field.get>(); + return cast_to_string(v.get_value(), v.get_scale()); } static std::string get_decimal64_value(const Field& field) { using ValueType = typename PrimitiveTypeTraits::CppType; - ValueType value = field.get(); - return cast_to_string(value, 0); + auto v = field.get>(); + return cast_to_string(v.get_value(), v.get_scale()); } static std::string get_decimal128_value(const Field& field) { using ValueType = typename PrimitiveTypeTraits::CppType; - ValueType value = field.get(); - return cast_to_string(value, 0); + auto v = field.get>(); + return cast_to_string(v.get_value(), v.get_scale()); } }; From cb05f67617a8c377dd6487aadf971d49b5c802f0 Mon Sep 17 00:00:00 2001 From: Kang Date: Wed, 1 Feb 2023 20:54:26 +0800 Subject: [PATCH 2/2] fix cast_to_string bug for TYPE_DECIMALV2 --- be/src/exec/olap_common.h | 2 +- be/src/runtime/runtime_predicate.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h index 0000ea8a9edea3..034696de6e1a33 100644 --- a/be/src/exec/olap_common.h +++ b/be/src/exec/olap_common.h @@ -45,7 +45,7 @@ std::string cast_to_string(T value, int scale) { std::stringstream ss; vectorized::write_text((int64_t)value, scale, ss); return ss.str(); - } else if constexpr (primitive_type == TYPE_DECIMAL128I || primitive_type == TYPE_DECIMALV2) { + } else if constexpr (primitive_type == TYPE_DECIMAL128I) { std::stringstream ss; vectorized::write_text((int128_t)value, scale, ss); return ss.str(); diff --git a/be/src/runtime/runtime_predicate.h b/be/src/runtime/runtime_predicate.h index 3cfdc296f36ef5..62ab5bcf4823f0 100644 --- a/be/src/runtime/runtime_predicate.h +++ b/be/src/runtime/runtime_predicate.h @@ -147,11 +147,13 @@ class RuntimePredicate { } static std::string get_decimalv2_value(const Field& field) { - // can NOT use PrimitiveTypeTraits::CppType since + // can NOT use PrimitiveTypeTraits::CppType since // it is DecimalV2Value and Decimal128 can not convert to it implicitly using ValueType = Decimal128::NativeType; auto v = field.get>(); - return cast_to_string(v.get_value(), v.get_scale()); + // use TYPE_DECIMAL128I instead of TYPE_DECIMALV2 since v.get_scale() + // is always 9 for DECIMALV2 + return cast_to_string(v.get_value(), v.get_scale()); } static std::string get_decimal32_value(const Field& field) {