github-actions[bot] commented on code in PR #63923:
URL: https://github.com/apache/doris/pull/63923#discussion_r3331568405
##########
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:
Please guard finite values that do not fit in `int64_t` before calling
`std::llround`. The SQL argument type is `DOUBLE`, so inputs like `select
human_readable_seconds(1e20)` are valid finite values. FE constant folding uses
`Math.round(Math.abs(seconds))`, which saturates at `Long.MAX_VALUE`, but
`std::llround` has a domain error when the rounded value is outside the
`int64_t` range and returns an implementation-defined value. With
`debug_skip_fold_constant=true`, BE execution can therefore produce a different
result from the folded FE path (or otherwise depend on libc behavior). Please
either reject out-of-range finite values consistently in both FE and BE, or
implement the same clamping/saturation semantics in both paths, and add a
regression case for it.
--
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]