30#include <unordered_map>
65 std::string_view str)
noexcept {
68 return InvalidArgument(
"Invalid snapshot reference type: {}", str);
73 static constexpr std::string_view kMainBranch =
"main";
91 return lhs.Equals(rhs);
96 bool Equals(
const Branch& other)
const;
99 struct ICEBERG_EXPORT
Tag {
110 bool Equals(
const Tag& other)
const;
120 std::optional<int64_t> max_ref_age_ms() const noexcept;
131 int64_t snapshot_id,
std::optional<int32_t> min_snapshots_to_keep =
std::nullopt,
132 std::optional<int64_t> max_snapshot_age_ms =
std::nullopt,
133 std::optional<int64_t> max_ref_age_ms =
std::nullopt);
142 int64_t snapshot_id,
std::optional<int64_t> max_ref_age_ms =
std::nullopt);
150 std::optional<int64_t> new_snapshot_id =
std::nullopt) const;
157 return lhs.Equals(rhs);
168 inline static const std::string kOperation =
"operation";
170 inline static const std::string kFirstRowId =
"first-row-id";
172 inline static const std::string kAddedRows =
"added-rows";
177 inline static const std::string kAddedDataFiles =
"added-data-files";
179 inline static const std::string kDeletedDataFiles =
"deleted-data-files";
181 inline static const std::string kTotalDataFiles =
"total-data-files";
184 inline static const std::string kAddedDeleteFiles =
"added-delete-files";
186 inline static const std::string kAddedEqDeleteFiles =
"added-equality-delete-files";
188 inline static const std::string kRemovedEqDeleteFiles =
"removed-equality-delete-files";
190 inline static const std::string kAddedPosDeleteFiles =
"added-position-delete-files";
192 inline static const std::string kRemovedPosDeleteFiles =
193 "removed-position-delete-files";
195 inline static const std::string kAddedDVs =
"added-dvs";
197 inline static const std::string kRemovedDVs =
"removed-dvs";
200 inline static const std::string kRemovedDeleteFiles =
"removed-delete-files";
203 inline static const std::string kTotalDeleteFiles =
"total-delete-files";
205 inline static const std::string kAddedRecords =
"added-records";
207 inline static const std::string kDeletedRecords =
"deleted-records";
209 inline static const std::string kTotalRecords =
"total-records";
211 inline static const std::string kAddedFileSize =
"added-files-size";
213 inline static const std::string kRemovedFileSize =
"removed-files-size";
215 inline static const std::string kTotalFileSize =
"total-files-size";
217 inline static const std::string kAddedPosDeletes =
"added-position-deletes";
219 inline static const std::string kRemovedPosDeletes =
"removed-position-deletes";
221 inline static const std::string kTotalPosDeletes =
"total-position-deletes";
223 inline static const std::string kAddedEqDeletes =
"added-equality-deletes";
225 inline static const std::string kRemovedEqDeletes =
"removed-equality-deletes";
227 inline static const std::string kTotalEqDeletes =
"total-equality-deletes";
230 inline static const std::string kDeletedDuplicatedFiles =
"deleted-duplicate-files";
232 inline static const std::string kChangedPartitionCountProp =
"changed-partition-count";
234 inline static const std::string kManifestsCreated =
"manifests-created";
236 inline static const std::string kManifestsKept =
"manifests-kept";
238 inline static const std::string kManifestsReplaced =
"manifests-replaced";
240 inline static const std::string kEntriesProcessed =
"entries-processed";
242 inline static const std::string kChangedPartitionPrefix =
"partitions.";
244 inline static const std::string kPartitionSummaryProp =
"partition-summaries-included";
249 inline static const std::string kWAPId =
"wap.id";
251 inline static const std::string kPublishedWAPId =
"published-wap-id";
253 inline static const std::string kSourceSnapshotId =
"source-snapshot-id";
255 inline static const std::string kEngineName =
"engine-name";
257 inline static const std::string kEngineVersion =
"engine-version";
259 inline static const std::string kReplacePartitions =
"replace-partitions";
269 class UpdateMetrics {
272 void AddTo(std::unordered_map<std::string, std::string>& builder)
const;
273 void AddedFile(
const DataFile& file);
274 void RemovedFile(
const DataFile& file);
276 void Merge(
const UpdateMetrics& other);
279 int64_t added_size_{0};
280 int64_t removed_size_{0};
281 int32_t added_files_{0};
282 int32_t removed_files_{0};
283 int32_t added_eq_delete_files_{0};
284 int32_t removed_eq_delete_files_{0};
285 int32_t added_pos_delete_files_{0};
286 int32_t removed_pos_delete_files_{0};
287 int32_t added_dvs_{0};
288 int32_t removed_dvs_{0};
289 int32_t added_delete_files_{0};
290 int32_t removed_delete_files_{0};
291 int64_t added_records_{0};
292 int64_t deleted_records_{0};
293 int64_t added_pos_deletes_{0};
294 int64_t removed_pos_deletes_{0};
295 int64_t added_eq_deletes_{0};
296 int64_t removed_eq_deletes_{0};
297 bool trust_size_and_delete_counts_{
true};
345 void Set(
const std::string& property,
const std::string& value);
355 std::unordered_map<std::string, std::string>
Build()
const;
360 std::string PartitionSummary(
const UpdateMetrics& metrics)
const;
362 std::unordered_map<std::string, std::string> properties_;
363 std::unordered_map<std::string, UpdateMetrics> partition_metrics_;
364 UpdateMetrics metrics_;
365 int32_t max_changed_partitions_for_summaries_{0};
366 int64_t deleted_duplicate_files_{0};
367 bool trust_partition_metrics_{
true};
377 inline static const std::string kAppend =
"append";
380 inline static const std::string kReplace =
"replace";
383 inline static const std::string kOverwrite =
"overwrite";
386 inline static const std::string kDelete =
"delete";
409 std::unordered_map<std::string, std::string>
summary;
422 int64_t sequence_number, int64_t snapshot_id,
423 std::optional<int64_t> parent_snapshot_id,
TimePointMs timestamp_ms,
424 std::string operation, std::unordered_map<std::string, std::string> summary,
425 std::optional<int32_t> schema_id, std::string manifest_list,
426 std::optional<int64_t> first_row_id = std::nullopt,
427 std::optional<int64_t> added_rows = std::nullopt);
461 return lhs.Equals(rhs);
466 bool Equals(
const Snapshot& other)
const;
502 using ManifestsCache = std::pair<std::vector<ManifestFile>,
size_t>;
509 std::shared_ptr<FileIO> file_io);
A partition spec for a Table.
Definition partition_spec.h:47
Reads a snapshot's manifests, loading and caching its manifest list on first access.
Definition snapshot.h:471
Result< std::span< ManifestFile > > DataManifests(std::shared_ptr< FileIO > file_io) const
Returns a ManifestFile for each data manifest in this snapshot.
const Snapshot & snapshot() const
Get the underlying Snapshot reference.
Definition snapshot.h:476
Result< std::span< ManifestFile > > DeleteManifests(std::shared_ptr< FileIO > file_io) const
Returns a ManifestFile for each delete manifest in this snapshot.
Result< std::span< ManifestFile > > Manifests(std::shared_ptr< FileIO > file_io) const
Returns all ManifestFile instances for either data or delete manifests in this snapshot.
Helper class for building snapshot summaries.
Definition snapshot.h:266
void Clear()
Clear all tracked metrics and properties.
void IncrementDuplicateDeletes(int32_t increment=1)
Increment the count of duplicate files deleted by a specific amount.
Status DeletedFile(const PartitionSpec &spec, const DataFile &file)
Track a data file being deleted from the snapshot.
void AddedManifest(const ManifestFile &manifest)
Track a manifest being added.
Status AddedFile(const PartitionSpec &spec, const DataFile &file)
Track a data file being added to the snapshot.
void Merge(const SnapshotSummaryBuilder &other)
Merge another builder's metrics into this one.
std::unordered_map< std::string, std::string > Build() const
Build the final summary map.
void SetPartitionSummaryLimit(int32_t max)
Set the maximum number of changed partitions before partition summaries will be excluded.
void Set(const std::string &property, const std::string &value)
Set a custom summary property.
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > TimePointMs
A time point in milliseconds.
Definition timepoint.h:33
ICEBERG_EXPORT constexpr Result< SnapshotRefType > SnapshotRefTypeFromString(std::string_view str) noexcept
Get the relative snapshot reference type from name.
Definition snapshot.h:64
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
void unreachable() noexcept
Marks a branch the program can never take.
Definition unreachable.h:35
SnapshotRefType
The type of snapshot reference.
Definition snapshot.h:44
@ kTag
Tags are labels for individual snapshots.
Define Result, Status, and error helpers.
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:63
Data operation that produce snapshots.
Definition snapshot.h:375
Entry in a manifest list.
Definition manifest_list.h:86
std::optional< int32_t > min_snapshots_to_keep
Definition snapshot.h:79
std::optional< int64_t > max_snapshot_age_ms
Definition snapshot.h:83
std::optional< int64_t > max_ref_age_ms
Definition snapshot.h:87
friend bool operator==(const Branch &lhs, const Branch &rhs)
Compare two branches for equality.
Definition snapshot.h:90
std::optional< int64_t > max_ref_age_ms
Definition snapshot.h:103
friend bool operator==(const Tag &lhs, const Tag &rhs)
Compare two tags for equality.
Definition snapshot.h:106
A reference to a snapshot, either a branch or a tag.
Definition snapshot.h:72
int64_t snapshot_id
A reference's snapshot ID. The tagged snapshot or latest snapshot of a branch.
Definition snapshot.h:114
std::variant< Branch, Tag > retention
Snapshot retention policy.
Definition snapshot.h:116
Optional Snapshot Summary Fields.
Definition snapshot.h:166
A snapshot of the data in a table at a point in time.
Definition snapshot.h:395
friend bool operator==(const Snapshot &lhs, const Snapshot &rhs)
Compare two snapshots for equality.
Definition snapshot.h:460
int64_t snapshot_id
A unique long ID.
Definition snapshot.h:397
std::optional< int64_t > first_row_id
The row-id of the first newly added row in this snapshot.
Definition snapshot.h:413
int64_t sequence_number
A monotonically increasing long that tracks the order of changes to a table.
Definition snapshot.h:401
std::optional< int32_t > schema_id
ID of the table's current schema when the snapshot was created.
Definition snapshot.h:411
static Result< std::unique_ptr< Snapshot > > Make(int64_t sequence_number, int64_t snapshot_id, std::optional< int64_t > parent_snapshot_id, TimePointMs timestamp_ms, std::string operation, std::unordered_map< std::string, std::string > summary, std::optional< int32_t > schema_id, std::string manifest_list, std::optional< int64_t > first_row_id=std::nullopt, std::optional< int64_t > added_rows=std::nullopt)
Create a new Snapshot instance with validation on the inputs.
Result< std::optional< int64_t > > AddedRows() const
The upper bound of number of rows with assigned row IDs in this snapshot.
TimePointMs timestamp_ms
Definition snapshot.h:404
std::optional< int64_t > added_rows
The upper bound of rows with assigned row IDs in this snapshot.
Definition snapshot.h:415
std::optional< std::string > key_id
Definition snapshot.h:418
std::optional< std::string_view > Operation() const
Return the name of the DataOperations data operation that produced this snapshot.
std::optional< int64_t > parent_snapshot_id
The snapshot ID of the snapshot's parent. Omitted for any snapshot with no parent.
Definition snapshot.h:399
Result< std::optional< int64_t > > FirstRowId() const
The row-id of the first newly added row in this snapshot.
std::string manifest_list
Definition snapshot.h:407
std::unordered_map< std::string, std::string > summary
A string map that summaries the snapshot changes, including operation.
Definition snapshot.h:409
Provide time point conversion helpers.
Portable stand-in for std::unreachable.