Skip to content

Commit b912924

Browse files
committed
feat: implement add column/delete column
1 parent 39a9c8b commit b912924

12 files changed

Lines changed: 1245 additions & 37 deletions

src/iceberg/json_internal.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ nlohmann::json ToJson(const SchemaField& field) {
227227
json[kName] = field.name();
228228
json[kRequired] = !field.optional();
229229
json[kType] = ToJson(*field.type());
230+
json[kDoc] = field.doc();
230231
return json;
231232
}
232233

@@ -463,9 +464,10 @@ Result<std::unique_ptr<SchemaField>> FieldFromJson(const nlohmann::json& json) {
463464
ICEBERG_ASSIGN_OR_RAISE(auto field_id, GetJsonValue<int32_t>(json, kId));
464465
ICEBERG_ASSIGN_OR_RAISE(auto name, GetJsonValue<std::string>(json, kName));
465466
ICEBERG_ASSIGN_OR_RAISE(auto required, GetJsonValue<bool>(json, kRequired));
467+
ICEBERG_ASSIGN_OR_RAISE(auto doc, GetJsonValueOrDefault<std::string>(json, kDoc));
466468

467469
return std::make_unique<SchemaField>(field_id, std::move(name), std::move(type),
468-
!required);
470+
!required, doc);
469471
}
470472

471473
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
@@ -165,6 +165,7 @@ if(ICEBERG_BUILD_BUNDLE)
165165
transaction_test.cc
166166
update_partition_spec_test.cc
167167
update_properties_test.cc
168+
update_schema_test.cc
168169
update_sort_order_test.cc)
169170

170171
add_iceberg_test(data_writer_test USE_BUNDLE SOURCES data_writer_test.cc)

src/iceberg/test/meson.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ iceberg_tests = {
9393
),
9494
},
9595
'roaring_test': {'sources': files('roaring_test.cc')},
96+
'table_update_test': {
97+
'sources': files(
98+
'transaction_test.cc',
99+
'update_partition_spec_test.cc',
100+
'update_properties_test.cc',
101+
'update_schema_test.cc',
102+
'update_sort_order_test.cc',
103+
),
104+
},
96105
}
97106

98107
if get_option('rest').enabled()

0 commit comments

Comments
 (0)