From ab2d7278e000a88a9b8bcef1fce51efddc44faff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20M=C4=99drek?= Date: Wed, 25 Sep 2024 13:19:03 +0200 Subject: [PATCH] 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 1f1b201fd875d9e4eca60f2dd01d2d1219efe19c) # Conflicts: # cql3/functions/user_function.cc --- cql3/functions/user_function.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cql3/functions/user_function.cc b/cql3/functions/user_function.cc index 2bae075ff6..eeb24590d3 100644 --- a/cql3/functions/user_function.cc +++ b/cql3/functions/user_function.cc @@ -13,6 +13,8 @@ #include +#include + 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 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) } }