zclllyybb commented on code in PR #61850:
URL: https://github.com/apache/doris/pull/61850#discussion_r3007992852
##########
be/src/exprs/function/function_utility.cpp:
##########
@@ -138,11 +141,124 @@ 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->convert_to_full_column_if_const();
Review Comment:
no need to do this. the outer framework did.
##########
be/src/exprs/function/function_utility.cpp:
##########
@@ -138,11 +141,124 @@ 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->convert_to_full_column_if_const();
+ 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();
+ for (size_t i = 0; i < input_rows_count; ++i) {
+ auto value = data_column->get_element(i);
+ auto text = _to_human_readable(value);
+ result_column->insert_data(text.data(), text.size());
+ }
+
+ block.replace_by_position(result, std::move(result_column));
+ return Status::OK();
+ }
+
+private:
+ static std::string _append_unit(int64_t value, const char* singular, const
char* plural) {
+ return std::to_string(value) + " " + (value == 1 ? singular : plural);
+ }
+
+ static std::string _to_human_readable(double seconds) {
Review Comment:
dont pass string as result. directly write to result column
##########
regression-test/suites/query_p0/sql_functions/datetime_functions/test_human_readable_seconds.groovy:
##########
Review Comment:
with AI, I think it's easy to make dozens or hundreds of different data to
cover the results as much as possible
##########
regression-test/suites/query_p0/sql_functions/datetime_functions/test_human_readable_seconds.groovy:
##########
Review Comment:
need check of consistency between FE and BE. btw, please add more data for
test.
--
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]