prakash-atul commented on code in PR #63923:
URL: https://github.com/apache/doris/pull/63923#discussion_r3331790397


##########
be/src/exprs/function/function_utility.cpp:
##########
@@ -138,11 +139,100 @@ class FunctionVersion : public IFunction {
     }
 };
 
+class FunctionHumanReadableSeconds : public IFunction {
+public:
+    static constexpr auto name = "human_readable_seconds";
+
+    static FunctionPtr create() { return 
std::make_shared<FunctionHumanReadableSeconds>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) const 
override {
+        return std::make_shared<DataTypeString>();
+    }
+
+    Status execute_impl(FunctionContext* /*context*/, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        const auto& argument_column = 
block.get_by_position(arguments[0]).column;
+        const auto* data_column = 
check_and_get_column<ColumnFloat64>(*argument_column);
+        if (data_column == nullptr) {
+            return Status::InvalidArgument("Illegal column {} of first 
argument of function {}",
+                                           argument_column->get_name(), name);
+        }
+
+        auto result_column = ColumnString::create();
+        result_column->reserve(input_rows_count);
+        std::string buffer;
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            double value = data_column->get_element(i);
+            if (std::isnan(value) || std::isinf(value)) {
+                return Status::InvalidArgument("Invalid argument value {} for 
function {}", value,
+                                               name);
+            }
+            buffer.clear();
+            to_human_readable(value, buffer);
+            result_column->insert_data(buffer.data(), buffer.size());
+        }
+
+        block.replace_by_position(result, std::move(result_column));
+        return Status::OK();
+    }
+
+private:
+    static void append_unit(std::string& out, int64_t value, const char* 
singular,
+                            const char* plural) {
+        if (!out.empty()) {
+            out += ", ";
+        }
+        out += std::to_string(value);
+        out += ' ';
+        out += (value == 1 ? singular : plural);
+    }
+
+    static void to_human_readable(double seconds, std::string& out) {
+        // Match Presto/Trino: round to whole seconds and ignore the sign.

Review Comment:
   Fixed in the latest push.
   
   The BE path now explicitly clamps very large finite DOUBLE values to 
`int64_t` max before calling `std::llround`, matching the FE constant-folding 
behavior (`Math.round` saturation to `Long.MAX_VALUE`) and avoiding 
implementation-defined overflow behavior.
   
   Added FE, BE, and regression coverage for `1e20` and `-1e20` as well.
   



-- 
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