Skip to content

Commit e5eb6e0

Browse files
authored
feat: implement add column/delete column (#486)
1 parent b7b5dd1 commit e5eb6e0

File tree

11 files changed

+1232
-37
lines changed

11 files changed

+1232
-37
lines changed

src/iceberg/json_internal.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ nlohmann::json ToJson(const SchemaField& field) {
277277
json[kName] = field.name();
278278
json[kRequired] = !field.optional();
279279
json[kType] = ToJson(*field.type());
280+
if (!field.doc().empty()) {
281+
json[kDoc] = field.doc();
282+
}
280283
return json;
281284
}
282285

@@ -513,9 +516,10 @@ Result<std::unique_ptr<SchemaField>> FieldFromJson(const nlohmann::json& json) {
513516
ICEBERG_ASSIGN_OR_RAISE(auto field_id, GetJsonValue<int32_t>(json, kId));
514517
ICEBERG_ASSIGN_OR_RAISE(auto name, GetJsonValue<std::string>(json, kName));
515518
ICEBERG_ASSIGN_OR_RAISE(auto required, GetJsonValue<bool>(json, kRequired));
519+
ICEBERG_ASSIGN_OR_RAISE(auto doc, GetJsonValueOrDefault<std::string>(json, kDoc));
516520

517521
return std::make_unique<SchemaField>(field_id, std::move(name), std::move(type),
518-
!required);
522+
!required, doc);
519523
}
520524

521525
Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json) {

src/iceberg/schema_field.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@
2020
#include "iceberg/schema_field.h"
2121

2222
#include <format>
23+
#include <string_view>
2324

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

2728
namespace iceberg {
2829

29-
SchemaField::SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
30-
bool optional, std::string doc)
30+
SchemaField::SchemaField(int32_t field_id, std::string_view name,
31+
std::shared_ptr<Type> type, bool optional, std::string_view doc)
3132
: field_id_(field_id),
32-
name_(std::move(name)),
33+
name_(name),
3334
type_(std::move(type)),
3435
optional_(optional),
35-
doc_(std::move(doc)) {}
36+
doc_(doc) {}
3637

37-
SchemaField SchemaField::MakeOptional(int32_t field_id, std::string name,
38-
std::shared_ptr<Type> type, std::string doc) {
39-
return {field_id, std::move(name), std::move(type), true, std::move(doc)};
38+
SchemaField SchemaField::MakeOptional(int32_t field_id, std::string_view name,
39+
std::shared_ptr<Type> type, std::string_view doc) {
40+
return {field_id, name, std::move(type), true, doc};
4041
}
4142

42-
SchemaField SchemaField::MakeRequired(int32_t field_id, std::string name,
43-
std::shared_ptr<Type> type, std::string doc) {
44-
return {field_id, std::move(name), std::move(type), false, std::move(doc)};
43+
SchemaField SchemaField::MakeRequired(int32_t field_id, std::string_view name,
44+
std::shared_ptr<Type> type, std::string_view doc) {
45+
return {field_id, name, std::move(type), false, doc};
4546
}
4647

4748
int32_t SchemaField::field_id() const { return field_id_; }

src/iceberg/schema_field.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
4646
/// \param[in] type The field type.
4747
/// \param[in] optional Whether values of this field are required or nullable.
4848
/// \param[in] doc Optional documentation string for the field.
49-
SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
50-
bool optional, std::string doc = {});
49+
SchemaField(int32_t field_id, std::string_view name, std::shared_ptr<Type> type,
50+
bool optional, std::string_view doc = {});
5151

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

5959
/// \brief Get the field ID.
6060
[[nodiscard]] int32_t field_id() const;

src/iceberg/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ if(ICEBERG_BUILD_BUNDLE)
170170
transaction_test.cc
171171
update_partition_spec_test.cc
172172
update_properties_test.cc
173+
update_schema_test.cc
173174
update_sort_order_test.cc)
174175

175176
add_iceberg_test(data_writer_test USE_BUNDLE SOURCES data_writer_test.cc)

0 commit comments

Comments
 (0)