jacktengg commented on code in PR #28027:
URL: https://github.com/apache/doris/pull/28027#discussion_r1417232266


##########
be/src/vec/core/types.h:
##########
@@ -495,38 +495,42 @@ static constexpr int max_decimal_string_length() {
            + 1;          // Add a space for negative sign
 }
 
+template <typename T>
+concept DecimalNativeTypeConcept = std::is_same_v<T, Int32> || 
std::is_same_v<T, Int64> ||
+                                   std::is_same_v<T, Int128> || 
std::is_same_v<T, wide::Int256>;
+
 /// Own FieldType for Decimal.
 /// It is only a "storage" for decimal. To perform operations, you also have 
to provide a scale (number of digits after point).
-template <typename T>
+template <DecimalNativeTypeConcept T>
 struct Decimal {
-    static_assert(std::is_same_v<T, Int32> || std::is_same_v<T, Int64> ||
-                  std::is_same_v<T, Int128>);
     using NativeType = T;
 
+    static constexpr bool IsInt256 = std::is_same_v<T, wide::Int256>;
+
     Decimal() = default;
     Decimal(Decimal<T>&&) = default;
     Decimal(const Decimal<T>&) = default;
 
-#define DECLARE_NUMERIC_CTOR(TYPE) \
-    Decimal(const TYPE& value_) : value(value_) {}
-
-    DECLARE_NUMERIC_CTOR(wide::Int256)
-    DECLARE_NUMERIC_CTOR(Int128)
-    DECLARE_NUMERIC_CTOR(Int32)
-    DECLARE_NUMERIC_CTOR(Int64)
-    DECLARE_NUMERIC_CTOR(UInt32)
-    DECLARE_NUMERIC_CTOR(UInt64)
-
-#undef DECLARE_NUMERIC_CTOR
-    Decimal(const Float32& value_) : value(value_) {
-        if constexpr (std::is_integral<T>::value) {
-            value = round(value_);
-        }
-    }
-    Decimal(const Float64& value_) : value(value_) {
-        if constexpr (std::is_integral<T>::value) {
-            value = round(value_);
+    explicit(IsInt256) Decimal(Int32 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(Int64 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(Int128 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(wide::Int256 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(UInt64 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(UInt32 value) noexcept : value(value) {}
+    explicit(IsInt256) Decimal(Float32 value) noexcept : 
value(type_round(value)) {}
+    explicit(IsInt256) Decimal(Float64 value) noexcept : 
value(type_round(value)) {}
+
+    /// If T is integral and non wide::Int256, the given value will be rounded 
to integer.
+    template <std::floating_point U>
+    static constexpr U type_round(U value) noexcept {
+        // When T is wide::Int256 will not round the value, according to the 
old implementation.
+        // Is it right?

Review Comment:
   Maybe it's a bug, should also roud for Int256



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to