Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/iceberg/json_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ nlohmann::json ToJson(const SchemaField& field) {
json[kName] = field.name();
json[kRequired] = !field.optional();
json[kType] = ToJson(*field.type());
if (!field.doc().empty()) {
json[kDoc] = field.doc();
}
return json;
}

Expand Down Expand Up @@ -463,9 +466,10 @@ Result<std::unique_ptr<SchemaField>> FieldFromJson(const nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto field_id, GetJsonValue<int32_t>(json, kId));
ICEBERG_ASSIGN_OR_RAISE(auto name, GetJsonValue<std::string>(json, kName));
ICEBERG_ASSIGN_OR_RAISE(auto required, GetJsonValue<bool>(json, kRequired));
ICEBERG_ASSIGN_OR_RAISE(auto doc, GetJsonValueOrDefault<std::string>(json, kDoc));

return std::make_unique<SchemaField>(field_id, std::move(name), std::move(type),
!required);
!required, doc);
}

Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json) {
Expand Down
21 changes: 11 additions & 10 deletions src/iceberg/schema_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@
#include "iceberg/schema_field.h"

#include <format>
#include <string_view>

#include "iceberg/type.h"
#include "iceberg/util/formatter.h" // IWYU pragma: keep

namespace iceberg {

SchemaField::SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
bool optional, std::string doc)
SchemaField::SchemaField(int32_t field_id, std::string_view name,
std::shared_ptr<Type> type, bool optional, std::string_view doc)
: field_id_(field_id),
name_(std::move(name)),
name_(name),
type_(std::move(type)),
optional_(optional),
doc_(std::move(doc)) {}
doc_(doc) {}

SchemaField SchemaField::MakeOptional(int32_t field_id, std::string name,
std::shared_ptr<Type> type, std::string doc) {
return {field_id, std::move(name), std::move(type), true, std::move(doc)};
SchemaField SchemaField::MakeOptional(int32_t field_id, std::string_view name,
std::shared_ptr<Type> type, std::string_view doc) {
return {field_id, name, std::move(type), true, doc};
}

SchemaField SchemaField::MakeRequired(int32_t field_id, std::string name,
std::shared_ptr<Type> type, std::string doc) {
return {field_id, std::move(name), std::move(type), false, std::move(doc)};
SchemaField SchemaField::MakeRequired(int32_t field_id, std::string_view name,
std::shared_ptr<Type> type, std::string_view doc) {
return {field_id, name, std::move(type), false, doc};
}

int32_t SchemaField::field_id() const { return field_id_; }
Expand Down
12 changes: 6 additions & 6 deletions src/iceberg/schema_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
/// \param[in] type The field type.
/// \param[in] optional Whether values of this field are required or nullable.
/// \param[in] doc Optional documentation string for the field.
SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
bool optional, std::string doc = {});
SchemaField(int32_t field_id, std::string_view name, std::shared_ptr<Type> type,
bool optional, std::string_view doc = {});

/// \brief Construct an optional (nullable) field.
static SchemaField MakeOptional(int32_t field_id, std::string name,
std::shared_ptr<Type> type, std::string doc = {});
static SchemaField MakeOptional(int32_t field_id, std::string_view name,
std::shared_ptr<Type> type, std::string_view doc = {});
/// \brief Construct a required (non-null) field.
static SchemaField MakeRequired(int32_t field_id, std::string name,
std::shared_ptr<Type> type, std::string doc = {});
static SchemaField MakeRequired(int32_t field_id, std::string_view name,
std::shared_ptr<Type> type, std::string_view doc = {});

/// \brief Get the field ID.
[[nodiscard]] int32_t field_id() const;
Expand Down
1 change: 1 addition & 0 deletions src/iceberg/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ if(ICEBERG_BUILD_BUNDLE)
transaction_test.cc
update_partition_spec_test.cc
update_properties_test.cc
update_schema_test.cc
update_sort_order_test.cc)

add_iceberg_test(data_writer_test USE_BUNDLE SOURCES data_writer_test.cc)
Expand Down
Loading
Loading