30#include <unordered_map>
64 std::string_view str)
noexcept {
67 return InvalidArgument(
"Invalid snapshot reference type: {}", str);
72 static constexpr std::string_view kMainBranch =
"main";
90 return lhs.Equals(rhs);
95 bool Equals(
const Branch& other)
const;
98 struct ICEBERG_EXPORT
Tag {
109 bool Equals(
const Tag& other)
const;
119 std::optional<int64_t> max_ref_age_ms() const noexcept;
130 int64_t snapshot_id,
std::optional<int32_t> min_snapshots_to_keep =
std::nullopt,
131 std::optional<int64_t> max_snapshot_age_ms =
std::nullopt,
132 std::optional<int64_t> max_ref_age_ms =
std::nullopt);
141 int64_t snapshot_id,
std::optional<int64_t> max_ref_age_ms =
std::nullopt);
149 std::optional<int64_t> new_snapshot_id =
std::nullopt) const;
152 Status Validate() const;
156 return lhs.Equals(rhs);
167 inline static const std::string kOperation =
"operation";
169 inline static const std::string kFirstRowId =
"first-row-id";
171 inline static const std::string kAddedRows =
"added-rows";
176 inline static const std::string kAddedDataFiles =
"added-data-files";
178 inline static const std::string kDeletedDataFiles =
"deleted-data-files";
180 inline static const std::string kTotalDataFiles =
"total-data-files";
183 inline static const std::string kAddedDeleteFiles =
"added-delete-files";
185 inline static const std::string kAddedEqDeleteFiles =
"added-equality-delete-files";
187 inline static const std::string kRemovedEqDeleteFiles =
"removed-equality-delete-files";
189 inline static const std::string kAddedPosDeleteFiles =
"added-position-delete-files";
191 inline static const std::string kRemovedPosDeleteFiles =
192 "removed-position-delete-files";
194 inline static const std::string kAddedDVs =
"added-dvs";
196 inline static const std::string kRemovedDVs =
"removed-dvs";
199 inline static const std::string kRemovedDeleteFiles =
"removed-delete-files";
202 inline static const std::string kTotalDeleteFiles =
"total-delete-files";
204 inline static const std::string kAddedRecords =
"added-records";
206 inline static const std::string kDeletedRecords =
"deleted-records";
208 inline static const std::string kTotalRecords =
"total-records";
210 inline static const std::string kAddedFileSize =
"added-files-size";
212 inline static const std::string kRemovedFileSize =
"removed-files-size";
214 inline static const std::string kTotalFileSize =
"total-files-size";
216 inline static const std::string kAddedPosDeletes =
"added-position-deletes";
218 inline static const std::string kRemovedPosDeletes =
"removed-position-deletes";
220 inline static const std::string kTotalPosDeletes =
"total-position-deletes";
222 inline static const std::string kAddedEqDeletes =
"added-equality-deletes";
224 inline static const std::string kRemovedEqDeletes =
"removed-equality-deletes";
226 inline static const std::string kTotalEqDeletes =
"total-equality-deletes";
229 inline static const std::string kDeletedDuplicatedFiles =
"deleted-duplicate-files";
231 inline static const std::string kChangedPartitionCountProp =
"changed-partition-count";
233 inline static const std::string kManifestsCreated =
"manifests-created";
235 inline static const std::string kManifestsKept =
"manifests-kept";
237 inline static const std::string kManifestsReplaced =
"manifests-replaced";
239 inline static const std::string kEntriesProcessed =
"entries-processed";
241 inline static const std::string kChangedPartitionPrefix =
"partitions.";
243 inline static const std::string kPartitionSummaryProp =
"partition-summaries-included";
248 inline static const std::string kWAPId =
"wap.id";
250 inline static const std::string kPublishedWAPId =
"published-wap-id";
252 inline static const std::string kSourceSnapshotId =
"source-snapshot-id";
254 inline static const std::string kEngineName =
"engine-name";
256 inline static const std::string kEngineVersion =
"engine-version";
258 inline static const std::string kReplacePartitions =
"replace-partitions";
268 class UpdateMetrics {
271 void AddTo(std::unordered_map<std::string, std::string>& builder)
const;
272 void AddedFile(
const DataFile& file);
273 void RemovedFile(
const DataFile& file);
275 void Merge(
const UpdateMetrics& other);
278 int64_t added_size_{0};
279 int64_t removed_size_{0};
280 int32_t added_files_{0};
281 int32_t removed_files_{0};
282 int32_t added_eq_delete_files_{0};
283 int32_t removed_eq_delete_files_{0};
284 int32_t added_pos_delete_files_{0};
285 int32_t removed_pos_delete_files_{0};
286 int32_t added_dvs_{0};
287 int32_t removed_dvs_{0};
288 int32_t added_delete_files_{0};
289 int32_t removed_delete_files_{0};
290 int64_t added_records_{0};
291 int64_t deleted_records_{0};
292 int64_t added_pos_deletes_{0};
293 int64_t removed_pos_deletes_{0};
294 int64_t added_eq_deletes_{0};
295 int64_t removed_eq_deletes_{0};
296 bool trust_size_and_delete_counts_{
true};
344 void Set(
const std::string& property,
const std::string& value);
354 std::unordered_map<std::string, std::string>
Build()
const;
359 std::string PartitionSummary(
const UpdateMetrics& metrics)
const;
361 std::unordered_map<std::string, std::string> properties_;
362 std::unordered_map<std::string, UpdateMetrics> partition_metrics_;
363 UpdateMetrics metrics_;
364 int32_t max_changed_partitions_for_summaries_{0};
365 int64_t deleted_duplicate_files_{0};
366 bool trust_partition_metrics_{
true};
376 inline static const std::string kAppend =
"append";
379 inline static const std::string kReplace =
"replace";
382 inline static const std::string kOverwrite =
"overwrite";
385 inline static const std::string kDelete =
"delete";
408 std::unordered_map<std::string, std::string>
summary;
418 int64_t sequence_number, int64_t snapshot_id,
419 std::optional<int64_t> parent_snapshot_id,
TimePointMs timestamp_ms,
420 std::string operation, std::unordered_map<std::string, std::string> summary,
421 std::optional<int32_t> schema_id, std::string manifest_list,
422 std::optional<int64_t> first_row_id = std::nullopt,
423 std::optional<int64_t> added_rows = std::nullopt);
457 return lhs.Equals(rhs);
462 bool Equals(
const Snapshot& other)
const;
499 using ManifestsCache = std::pair<std::vector<ManifestFile>,
size_t>;
506 std::shared_ptr<FileIO> file_io);
A partition spec for a Table.
Definition partition_spec.h:47
A snapshot with cached manifest loading capabilities.
Definition snapshot.h:468
const Snapshot & snapshot() const
Get the underlying Snapshot reference.
Definition snapshot.h:473
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.
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 > > DataManifests(std::shared_ptr< FileIO > file_io) const
Returns a ManifestFile for each data manifest in this snapshot.
Helper class for building snapshot summaries.
Definition snapshot.h:265
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.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
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:63
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
SnapshotRefType
The type of snapshot reference.
Definition snapshot.h:43
@ kTag
Tags are labels for individual snapshots.
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:62
Data operation that produce snapshots.
Definition snapshot.h:374
Entry in a manifest list.
Definition manifest_list.h:85
std::optional< int32_t > min_snapshots_to_keep
Definition snapshot.h:78
std::optional< int64_t > max_snapshot_age_ms
Definition snapshot.h:82
std::optional< int64_t > max_ref_age_ms
Definition snapshot.h:86
friend bool operator==(const Branch &lhs, const Branch &rhs)
Compare two branches for equality.
Definition snapshot.h:89
std::optional< int64_t > max_ref_age_ms
Definition snapshot.h:102
friend bool operator==(const Tag &lhs, const Tag &rhs)
Compare two tags for equality.
Definition snapshot.h:105
A reference to a snapshot, either a branch or a tag.
Definition snapshot.h:71
int64_t snapshot_id
A reference's snapshot ID. The tagged snapshot or latest snapshot of a branch.
Definition snapshot.h:113
std::variant< Branch, Tag > retention
Snapshot retention policy.
Definition snapshot.h:115
Optional Snapshot Summary Fields.
Definition snapshot.h:165
A snapshot of the data in a table at a point in time.
Definition snapshot.h:394
friend bool operator==(const Snapshot &lhs, const Snapshot &rhs)
Compare two snapshots for equality.
Definition snapshot.h:456
int64_t snapshot_id
A unique long ID.
Definition snapshot.h:396
std::optional< int64_t > first_row_id
The row-id of the first newly added row in this snapshot.
Definition snapshot.h:412
int64_t sequence_number
A monotonically increasing long that tracks the order of changes to a table.
Definition snapshot.h:400
std::optional< int32_t > schema_id
ID of the table's current schema when the snapshot was created.
Definition snapshot.h:410
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:403
std::optional< int64_t > added_rows
The upper bound of rows with assigned row IDs in this snapshot.
Definition snapshot.h:414
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:398
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:406
std::unordered_map< std::string, std::string > summary
A string map that summaries the snapshot changes, including operation.
Definition snapshot.h:408
Provide time point conversion helpers.