cql3/functions/user_function: Use fmt to format create statement

We replace `std::ostringstream` with views and formatting
using fmt to improve readability of the code.

(cherry picked from commit 1f1b201fd8)

# Conflicts:
#	cql3/functions/user_function.cc
This commit is contained in:
Dawid Mędrek
2024-09-25 13:19:03 +02:00
committed by Mergify
parent 190385ee2b
commit ab2d7278e0

View File

@@ -13,6 +13,8 @@
#include <seastar/core/thread.hh>
#include <ranges>
namespace cql3 {
namespace functions {
@@ -79,6 +81,7 @@ std::ostream& user_function::describe(std::ostream& os) const {
}
os << ")\n";
<<<<<<< HEAD
if (_called_on_null_input) {
os << "CALLED";
} else {
@@ -92,6 +95,33 @@ std::ostream& user_function::describe(std::ostream& os) const {
<< "$$;";
return os;
=======
auto arg_type_range = _arg_types | std::views::transform(std::mem_fn(&abstract_type::cql3_type_name));
auto arg_range = std::views::zip(_arg_names, arg_type_range)
| std::views::transform([] (std::tuple<std::string_view, std::string_view> arg) {
const auto [name, type] = arg;
return seastar::format("{} {}", name, type);
});
return seastar::format("CREATE FUNCTION {}.{}({})\n"
"{} ON NULL INPUT\n"
"RETURNS {}\n"
"LANGUAGE {}\n"
"AS $${}$$;",
cql3::util::maybe_quote(name().keyspace), cql3::util::maybe_quote(name().name), fmt::join(arg_range, ", "),
_called_on_null_input ? "CALLED" : "RETURNS NULL",
_return_type->cql3_type_name(),
_language,
_body);
});
return description {
.keyspace = name().keyspace,
.type = "function",
.name = name().name,
.create_statement = std::move(maybe_create_statement)
};
>>>>>>> 1f1b201fd8 (cql3/functions/user_function: Use fmt to format create statement)
}
}