From f673442b6ff4eb95dd4bc5744fdaffdeb85aa9d4 Mon Sep 17 00:00:00 2001 From: Andrew Wong Date: Fri, 27 Sep 2024 08:49:04 -0700 Subject: [PATCH] iceberg: switch to string_view Switches serialization interfaces to use std::string_view instead of const sstring&, as it's more generic. --- src/v/iceberg/manifest_avro.cc | 4 ++-- src/v/iceberg/schema_avro.cc | 4 ++-- src/v/iceberg/schema_avro.h | 2 +- src/v/iceberg/snapshot_json.cc | 4 ++-- src/v/iceberg/transform_json.cc | 2 +- src/v/iceberg/transform_json.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/v/iceberg/manifest_avro.cc b/src/v/iceberg/manifest_avro.cc index ca549188758c2..0c7ebacf9f8a4 100644 --- a/src/v/iceberg/manifest_avro.cc +++ b/src/v/iceberg/manifest_avro.cc @@ -35,9 +35,9 @@ namespace iceberg { namespace { -schema schema_from_str(const std::string& s) { +schema schema_from_str(std::string_view s) { json::Document parsed_schema; - parsed_schema.Parse(s); + parsed_schema.Parse(s.data(), s.size()); return parse_schema(parsed_schema); } diff --git a/src/v/iceberg/schema_avro.cc b/src/v/iceberg/schema_avro.cc index 95465df029aa0..528f8a62c8651 100644 --- a/src/v/iceberg/schema_avro.cc +++ b/src/v/iceberg/schema_avro.cc @@ -188,8 +188,8 @@ avro::Schema field_to_avro(const nested_field& field) { } avro::Schema -struct_type_to_avro(const struct_type& type, const ss::sstring& name) { - avro::RecordSchema avro_schema(name); +struct_type_to_avro(const struct_type& type, std::string_view name) { + avro::RecordSchema avro_schema(std::string{name}); const auto& fields = type.fields; for (const auto& field_ptr : fields) { const auto child_schema = field_to_avro(*field_ptr); diff --git a/src/v/iceberg/schema_avro.h b/src/v/iceberg/schema_avro.h index 378b834f6ae24..11d8d733b5b4d 100644 --- a/src/v/iceberg/schema_avro.h +++ b/src/v/iceberg/schema_avro.h @@ -20,7 +20,7 @@ namespace iceberg { // The resulting schema is annotated with Iceberg attributes (e.g. 'field-id', // 'element-id'). avro::Schema field_to_avro(const nested_field& field); -avro::Schema struct_type_to_avro(const struct_type&, const ss::sstring& name); +avro::Schema struct_type_to_avro(const struct_type&, std::string_view name); // Translates the given Avro schema into its corresponding field/type, throwing // an exception if the schema is not a valid Iceberg schema (e.g. missing diff --git a/src/v/iceberg/snapshot_json.cc b/src/v/iceberg/snapshot_json.cc index 22b29cc45eeaa..2b13922a1a136 100644 --- a/src/v/iceberg/snapshot_json.cc +++ b/src/v/iceberg/snapshot_json.cc @@ -34,7 +34,7 @@ constexpr std::string_view operation_to_str(snapshot_operation o) { } } -snapshot_operation operation_from_str(const ss::sstring& operation_str) { +snapshot_operation operation_from_str(std::string_view operation_str) { using enum snapshot_operation; return string_switch(operation_str) .match(operation_to_str(append), append) @@ -53,7 +53,7 @@ constexpr std::string_view ref_type_to_str(snapshot_ref_type t) { } } -snapshot_ref_type ref_type_from_str(const ss::sstring& ref_type_str) { +snapshot_ref_type ref_type_from_str(std::string_view ref_type_str) { using enum snapshot_ref_type; return string_switch(ref_type_str) .match(ref_type_to_str(tag), tag) diff --git a/src/v/iceberg/transform_json.cc b/src/v/iceberg/transform_json.cc index 827134fd376b4..6fbfd4a6c90fd 100644 --- a/src/v/iceberg/transform_json.cc +++ b/src/v/iceberg/transform_json.cc @@ -39,7 +39,7 @@ ss::sstring transform_to_str(const transform& t) { return std::visit(transform_str_visitor{}, t); } -transform transform_from_str(const ss::sstring& s) { +transform transform_from_str(std::string_view s) { if (s.starts_with("bucket")) { auto n_str = extract_between('[', ']', s); auto n = std::stoul(ss::sstring(n_str)); diff --git a/src/v/iceberg/transform_json.h b/src/v/iceberg/transform_json.h index c27a9f6ec2bd0..7e3fbecdc4d27 100644 --- a/src/v/iceberg/transform_json.h +++ b/src/v/iceberg/transform_json.h @@ -18,6 +18,6 @@ namespace iceberg { // NOTE: while there are no complex JSON types here, the transforms are // expected to be serialized as a part of JSON files (e.g. table metadata). ss::sstring transform_to_str(const transform&); -transform transform_from_str(const ss::sstring&); +transform transform_from_str(std::string_view); } // namespace iceberg