Skip to content

Commit 6c68501

Browse files
committed
feat: add snapshot update
1 parent dba8f92 commit 6c68501

File tree

14 files changed

+652
-12
lines changed

14 files changed

+652
-12
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ set(ICEBERG_SOURCES
7777
transform_function.cc
7878
type.cc
7979
update/pending_update.cc
80+
update/snapshot_update.cc
8081
update/update_properties.cc
8182
util/bucket_util.cc
8283
util/conversions.cc

src/iceberg/manifest/manifest_writer.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,23 @@ Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::MakeV3Writer(
447447
new ManifestListWriter(std::move(writer), std::move(adapter)));
448448
}
449449

450+
Result<std::unique_ptr<ManifestListWriter>> ManifestListWriter::Make(
451+
int8_t format_version, int64_t snapshot_id, std::optional<int64_t> parent_snapshot_id,
452+
std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io,
453+
int64_t sequence_number, int64_t first_row_id) {
454+
switch (format_version) {
455+
case 1:
456+
return MakeV1Writer(snapshot_id, parent_snapshot_id, manifest_list_location,
457+
file_io);
458+
case 2:
459+
return MakeV2Writer(snapshot_id, parent_snapshot_id, sequence_number,
460+
manifest_list_location, file_io);
461+
case 3:
462+
return MakeV3Writer(snapshot_id, parent_snapshot_id, sequence_number, first_row_id,
463+
manifest_list_location, file_io);
464+
default:
465+
std::unreachable();
466+
}
467+
}
468+
450469
} // namespace iceberg

src/iceberg/manifest/manifest_writer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ class ICEBERG_EXPORT ManifestListWriter {
236236
int64_t sequence_number, int64_t first_row_id,
237237
std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io);
238238

239+
/// \brief Creates a writer for the manifest list based on the format version.
240+
/// \param format_version Format version of the manifest list.
241+
/// \param snapshot_id ID of the snapshot.
242+
/// \param parent_snapshot_id ID of the parent snapshot.
243+
/// \param manifest_list_location Path to the manifest list file.
244+
/// \param file_io File IO implementation to use.
245+
/// \param sequence_number Sequence number of the snapshot.
246+
/// \param first_row_id First row ID of the snapshot.
247+
/// \return A Result containing the writer or an error.
248+
static Result<std::unique_ptr<ManifestListWriter>> Make(
249+
int8_t format_version, int64_t snapshot_id,
250+
std::optional<int64_t> parent_snapshot_id, std::string_view manifest_list_location,
251+
std::shared_ptr<FileIO> file_io, int64_t sequence_number = 0,
252+
int64_t first_row_id = 0);
253+
239254
private:
240255
// Private constructor for internal use only, use the static Make*Writer methods
241256
// instead.

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_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/transaction.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class ICEBERG_EXPORT Transaction : public std::enable_shared_from_this<Transacti
6868
/// \brief Apply the pending changes to current table.
6969
Status Apply(std::vector<std::unique_ptr<TableUpdate>> updates);
7070

71-
friend class PendingUpdate; // Need to access the Apply method.
71+
/// \brief Friends to access the Apply method.
72+
friend class PendingUpdate;
73+
template <typename T>
74+
friend class SnapshotUpdate;
7275

7376
private:
7477
// The table that this transaction will update.

src/iceberg/type_fwd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class Transaction;
178178
/// \brief Update family.
179179
class PendingUpdate;
180180
class UpdateProperties;
181+
template <typename T>
182+
class SnapshotUpdate;
181183

182184
/// ----------------------------------------------------------------------------
183185
/// TODO: Forward declarations below are not added yet.

src/iceberg/update/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
# under the License.
1717

1818
install_headers(
19-
['pending_update.h', 'update_properties.h'],
19+
['pending_update.h', 'update_properties.h', 'snapshot_update.h'],
2020
subdir: 'iceberg/update',
2121
)

0 commit comments

Comments
 (0)