zclllyybb commented on code in PR #53742:
URL: https://github.com/apache/doris/pull/53742#discussion_r2246875835


##########
be/src/vec/functions/date_time_transforms.h:
##########
@@ -293,26 +328,80 @@ struct FromUnixTimeImpl {
             auto len = strlen(buf);
             res_data.insert(buf, buf + len);
             offset += len;
-            return false;
+        } else {
+            // No buffer is needed here because these specially optimized 
formats have fixed lengths,
+            // and sufficient memory has already been reserved.
+            auto len = Impl::date_to_str(dt, (char*)res_data.data() + offset);
+            offset += len;
+        }
+        return false;
+    }
+};
+
+// only new verison
+template <bool WithStringArg>
+struct FromUnixTimeDecimalImpl {
+    using CppType = Decimal64;
+    using ArgType = Int64;
+    static constexpr PrimitiveType FromPType = TYPE_DECIMAL64;
+    constexpr static short Scale = 6; // same with argument's scale in FE's 
signature
 
+    static DataTypes get_variadic_argument_types() {
+        if constexpr (WithStringArg) {
+            return {std::make_shared<DataTypeDecimal64>(),
+                    std::make_shared<vectorized::DataTypeString>()};
         } else {
-            DateV2Value<DateTimeV2ValueType> dt;
-            if (val < 0 || val > TIMESTAMP_VALID_MAX) {
-                return true;
-            }
-            dt.from_unixtime(val, time_zone);
+            return {std::make_shared<DataTypeDecimal64>()};
+        }
+    }
+    static constexpr auto name = "from_unixtime_new";
 
-            if (!dt.is_valid_date()) {
+    [[nodiscard]] static bool check_valid(const ArgType& val) {
+        if (val < 0) [[unlikely]] {
+            return false;
+        }
+        return true;
+    }
+
+    static DateV2Value<DateTimeV2ValueType> get_datetime_value(const ArgType& 
interger,
+                                                               const ArgType& 
fraction,
+                                                               const 
cctz::time_zone& time_zone) {
+        DateV2Value<DateTimeV2ValueType> dt;
+        // 9 is nanoseconds, our input's scale is 6
+        dt.from_unixtime(interger, (int32_t)fraction * common::exp10_i32(9 - 
Scale), time_zone, 6);
+        return dt;
+    }
+
+    // return true if null(result is invalid)
+    template <typename Impl>
+    static bool execute_decimal(const ArgType& interger, const ArgType& 
fraction, StringRef format,
+                                ColumnString::Chars& res_data, size_t& offset,
+                                const cctz::time_zone& time_zone) {
+        if (!check_valid(interger + bool(fraction))) {

Review Comment:
   should use std::signbit rather than casting to bool...



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to