Skip to content

Commit 3c9c444

Browse files
committed
feat: add snapshot update
1 parent cf0fd37 commit 3c9c444

16 files changed

+795
-14
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ set(ICEBERG_SOURCES
8080
transform_function.cc
8181
type.cc
8282
update/pending_update.cc
83+
update/snapshot_update.cc
8384
update/update_partition_spec.cc
8485
update/update_properties.cc
8586
update/update_sort_order.cc

src/iceberg/table.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
5050

5151
virtual ~Table();
5252

53-
/// \brief Return the identifier of this table
53+
/// \brief Returns the identifier of this table
5454
const TableIdentifier& name() const { return identifier_; }
5555

5656
/// \brief Returns the UUID of the table
@@ -59,40 +59,40 @@ class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
5959
/// \brief Return the schema for this table, return NotFoundError if not found
6060
Result<std::shared_ptr<Schema>> schema() const;
6161

62-
/// \brief Return a map of schema for this table
62+
/// \brief Returns a map of schema for this table
6363
Result<
6464
std::reference_wrapper<const std::unordered_map<int32_t, std::shared_ptr<Schema>>>>
6565
schemas() const;
6666

67-
/// \brief Return the partition spec for this table, return NotFoundError if not found
67+
/// \brief Returns the partition spec for this table, return NotFoundError if not found
6868
Result<std::shared_ptr<PartitionSpec>> spec() const;
6969

70-
/// \brief Return a map of partition specs for this table
70+
/// \brief Returns a map of partition specs for this table
7171
Result<std::reference_wrapper<
7272
const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>>>
7373
specs() const;
7474

75-
/// \brief Return the sort order for this table, return NotFoundError if not found
75+
/// \brief Returns the sort order for this table, return NotFoundError if not found
7676
Result<std::shared_ptr<SortOrder>> sort_order() const;
7777

78-
/// \brief Return a map of sort order IDs to sort orders for this table
78+
/// \brief Returns a map of sort order IDs to sort orders for this table
7979
Result<std::reference_wrapper<
8080
const std::unordered_map<int32_t, std::shared_ptr<SortOrder>>>>
8181
sort_orders() const;
8282

83-
/// \brief Return a map of string properties for this table
83+
/// \brief Returns the properties of this table
8484
const TableProperties& properties() const;
8585

86-
/// \brief Return the table's metadata file location
86+
/// \brief Returns the table's metadata file location
8787
std::string_view metadata_file_location() const;
8888

89-
/// \brief Return the table's base location
89+
/// \brief Returns the table's base location
9090
std::string_view location() const;
9191

9292
/// \brief Returns the time when this table was last updated
9393
TimePointMs last_updated_ms() const;
9494

95-
/// \brief Return the table's current snapshot, return NotFoundError if not found
95+
/// \brief Returns the table's current snapshot, return NotFoundError if not found
9696
Result<std::shared_ptr<Snapshot>> current_snapshot() const;
9797

9898
/// \brief Get the snapshot of this table with the given id

src/iceberg/table_metadata.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ class TableMetadataBuilder::Impl {
591591
Status RemoveSchemas(const std::unordered_set<int32_t>& schema_ids);
592592
Result<int32_t> AddSchema(const Schema& schema, int32_t new_last_column_id);
593593
void SetLocation(std::string_view location);
594+
Status AddSnapshot(const Snapshot& snapshot);
595+
Status SetBranchSnapshot(int64_t snapshot_id, const std::string& branch);
594596

595597
Result<std::unique_ptr<TableMetadata>> Build();
596598

@@ -1207,12 +1209,14 @@ TableMetadataBuilder& TableMetadataBuilder::AddSortOrder(
12071209

12081210
TableMetadataBuilder& TableMetadataBuilder::AddSnapshot(
12091211
std::shared_ptr<Snapshot> snapshot) {
1210-
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
1212+
ICEBERG_BUILDER_RETURN_IF_ERROR(impl_->AddSnapshot(*snapshot));
1213+
return *this;
12111214
}
12121215

12131216
TableMetadataBuilder& TableMetadataBuilder::SetBranchSnapshot(int64_t snapshot_id,
12141217
const std::string& branch) {
1215-
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
1218+
ICEBERG_BUILDER_RETURN_IF_ERROR(impl_->SetBranchSnapshot(snapshot_id, branch));
1219+
return *this;
12161220
}
12171221

12181222
TableMetadataBuilder& TableMetadataBuilder::SetRef(const std::string& name,

src/iceberg/table_properties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ class ICEBERG_EXPORT TableProperties : public ConfigBase<TableProperties> {
244244
inline static Entry<int64_t> kDeleteTargetFileSizeBytes{
245245
"write.delete.target-file-size-bytes", int64_t{64} * 1024 * 1024}; // 64 MB
246246

247+
inline static Entry<bool> kSnapshotIdInheritanceEnabled{
248+
"compatibility.snapshot-id-inheritance.enabled", false};
249+
247250
// Garbage collection properties
248251

249252
inline static Entry<bool> kGcEnabled{"gc.enabled", true};

src/iceberg/table_update.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void SetDefaultSortOrder::GenerateRequirements(TableUpdateContext& context) cons
134134
// AddSnapshot
135135

136136
void AddSnapshot::ApplyTo(TableMetadataBuilder& builder) const {
137-
throw IcebergError(std::format("{} not implemented", __FUNCTION__));
137+
builder.AddSnapshot(snapshot_);
138138
}
139139

140140
void AddSnapshot::GenerateRequirements(TableUpdateContext& context) const {

src/iceberg/transaction.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ Status Transaction::Apply(PendingUpdate& update) {
105105
metadata_builder_->AddPartitionSpec(std::move(result.spec));
106106
}
107107
} break;
108+
case PendingUpdate::Kind::kUpdateSnapshot: {
109+
auto& update_snapshot = internal::checked_cast<SnapshotUpdate&>(update);
110+
ICEBERG_ASSIGN_OR_RAISE(auto result, update_snapshot.Apply());
111+
metadata_builder_->AddSnapshot(std::move(result.snapshot));
112+
} break;
108113
default:
109114
return NotSupported("Unsupported pending update: {}",
110115
static_cast<int32_t>(update.kind()));

src/iceberg/transaction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class ICEBERG_EXPORT Transaction : public std::enable_shared_from_this<Transacti
7777
/// \brief Apply the pending changes to current table.
7878
Status Apply(PendingUpdate& updates);
7979

80-
friend class PendingUpdate; // Need to access the Apply method.
80+
/// \brief Friends to access the Apply method.
81+
friend class PendingUpdate;
82+
friend class SnapshotUpdate;
8183

8284
private:
8385
// The table that this transaction will update.

src/iceberg/type_fwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class PendingUpdate;
183183
class UpdatePartitionSpec;
184184
class UpdateProperties;
185185
class UpdateSortOrder;
186+
class SnapshotUpdate;
186187

187188
/// ----------------------------------------------------------------------------
188189
/// TODO: Forward declarations below are not added yet.

src/iceberg/update/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
install_headers(
1919
[
2020
'pending_update.h',
21+
'snapshot_update.h',
2122
'update_partition_spec.h',
2223
'update_sort_order.h',
2324
'update_properties.h',

src/iceberg/update/pending_update.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ICEBERG_EXPORT PendingUpdate : public ErrorCollector {
4545
kUpdatePartitionSpec,
4646
kUpdateProperties,
4747
kUpdateSortOrder,
48+
kUpdateSnapshot,
4849
};
4950

5051
/// \brief Return the kind of this pending update.

0 commit comments

Comments
 (0)