28#include <unordered_map>
29#include <unordered_set>
45 enum class Kind : uint8_t {
47 kUpgradeFormatVersion,
51 kSetDefaultPartitionSpec,
52 kRemovePartitionSpecs,
65 kSetPartitionStatistics,
66 kRemovePartitionStatistics,
74 virtual Kind
kind()
const = 0;
103 virtual std::unique_ptr<TableUpdate>
Clone()
const = 0;
118 const std::string&
uuid()
const {
return uuid_; }
124 Kind
kind()
const override {
return Kind::kAssignUUID; }
128 std::unique_ptr<TableUpdate>
Clone()
const override;
138 : format_version_(format_version) {}
140 int8_t format_version()
const {
return format_version_; }
146 Kind
kind()
const override {
return Kind::kUpgradeFormatVersion; }
150 std::unique_ptr<TableUpdate>
Clone()
const override;
153 int8_t format_version_;
159 explicit AddSchema(std::shared_ptr<Schema> schema, int32_t last_column_id)
160 : schema_(std::move(schema)), last_column_id_(last_column_id) {}
162 const std::shared_ptr<Schema>& schema()
const {
return schema_; }
164 int32_t last_column_id()
const {
return last_column_id_; }
170 Kind
kind()
const override {
return Kind::kAddSchema; }
174 std::unique_ptr<TableUpdate>
Clone()
const override;
177 std::shared_ptr<Schema> schema_;
178 int32_t last_column_id_;
186 int32_t schema_id()
const {
return schema_id_; }
192 Kind
kind()
const override {
return Kind::kSetCurrentSchema; }
196 std::unique_ptr<TableUpdate>
Clone()
const override;
206 : spec_(std::move(spec)) {}
208 const std::shared_ptr<PartitionSpec>& spec()
const {
return spec_; }
214 Kind
kind()
const override {
return Kind::kAddPartitionSpec; }
218 std::unique_ptr<TableUpdate>
Clone()
const override;
221 std::shared_ptr<PartitionSpec> spec_;
229 int32_t spec_id()
const {
return spec_id_; }
235 Kind
kind()
const override {
return Kind::kSetDefaultPartitionSpec; }
239 std::unique_ptr<TableUpdate>
Clone()
const override;
249 : spec_ids_(std::move(spec_ids)) {}
251 const std::vector<int32_t>& spec_ids()
const {
return spec_ids_; }
257 Kind
kind()
const override {
return Kind::kRemovePartitionSpecs; }
261 std::unique_ptr<TableUpdate>
Clone()
const override;
264 std::vector<int32_t> spec_ids_;
270 explicit RemoveSchemas(std::unordered_set<int32_t> schema_ids)
271 : schema_ids_(std::move(schema_ids)) {}
273 const std::unordered_set<int32_t>& schema_ids()
const {
return schema_ids_; }
279 Kind
kind()
const override {
return Kind::kRemoveSchemas; }
283 std::unique_ptr<TableUpdate>
Clone()
const override;
286 std::unordered_set<int32_t> schema_ids_;
292 explicit AddSortOrder(std::shared_ptr<SortOrder> sort_order)
293 : sort_order_(std::move(sort_order)) {}
295 const std::shared_ptr<SortOrder>& sort_order()
const {
return sort_order_; }
301 Kind
kind()
const override {
return Kind::kAddSortOrder; }
305 std::unique_ptr<TableUpdate>
Clone()
const override;
308 std::shared_ptr<SortOrder> sort_order_;
316 int32_t sort_order_id()
const {
return sort_order_id_; }
322 Kind
kind()
const override {
return Kind::kSetDefaultSortOrder; }
326 std::unique_ptr<TableUpdate>
Clone()
const override;
329 int32_t sort_order_id_;
335 explicit AddSnapshot(std::shared_ptr<Snapshot> snapshot)
336 : snapshot_(std::move(snapshot)) {}
338 const std::shared_ptr<Snapshot>& snapshot()
const {
return snapshot_; }
344 Kind
kind()
const override {
return Kind::kAddSnapshot; }
348 std::unique_ptr<TableUpdate>
Clone()
const override;
351 std::shared_ptr<Snapshot> snapshot_;
358 : snapshot_ids_(std::move(snapshot_ids)) {}
360 const std::vector<int64_t>& snapshot_ids()
const {
return snapshot_ids_; }
366 Kind
kind()
const override {
return Kind::kRemoveSnapshots; }
370 std::unique_ptr<TableUpdate>
Clone()
const override;
373 std::vector<int64_t> snapshot_ids_;
379 explicit RemoveSnapshotRef(std::string ref_name) : ref_name_(std::move(ref_name)) {}
381 const std::string& ref_name()
const {
return ref_name_; }
387 Kind
kind()
const override {
return Kind::kRemoveSnapshotRef; }
391 std::unique_ptr<TableUpdate>
Clone()
const override;
394 std::string ref_name_;
401 std::optional<int32_t> min_snapshots_to_keep = std::nullopt,
402 std::optional<int64_t> max_snapshot_age_ms = std::nullopt,
403 std::optional<int64_t> max_ref_age_ms = std::nullopt)
404 : ref_name_(std::move(ref_name)),
405 snapshot_id_(snapshot_id),
407 min_snapshots_to_keep_(min_snapshots_to_keep),
408 max_snapshot_age_ms_(max_snapshot_age_ms),
409 max_ref_age_ms_(max_ref_age_ms) {}
412 : ref_name_(std::move(ref_name)), snapshot_id_(ref.
snapshot_id), type_(ref.type()) {
413 if (type_ == SnapshotRefType::kBranch) {
414 const auto& branch = std::get<SnapshotRef::Branch>(ref.
retention);
415 min_snapshots_to_keep_ = branch.min_snapshots_to_keep;
416 max_snapshot_age_ms_ = branch.max_snapshot_age_ms;
417 max_ref_age_ms_ = branch.max_ref_age_ms;
419 const auto& tag = std::get<SnapshotRef::Tag>(ref.
retention);
420 max_ref_age_ms_ = tag.max_ref_age_ms;
424 const std::string& ref_name()
const {
return ref_name_; }
425 int64_t snapshot_id()
const {
return snapshot_id_; }
427 const std::optional<int32_t>& min_snapshots_to_keep()
const {
428 return min_snapshots_to_keep_;
430 const std::optional<int64_t>& max_snapshot_age_ms()
const {
431 return max_snapshot_age_ms_;
433 const std::optional<int64_t>& max_ref_age_ms()
const {
return max_ref_age_ms_; }
439 Kind
kind()
const override {
return Kind::kSetSnapshotRef; }
443 std::unique_ptr<TableUpdate>
Clone()
const override;
446 std::string ref_name_;
447 int64_t snapshot_id_;
449 std::optional<int32_t> min_snapshots_to_keep_;
450 std::optional<int64_t> max_snapshot_age_ms_;
451 std::optional<int64_t> max_ref_age_ms_;
457 explicit SetProperties(std::unordered_map<std::string, std::string> updated)
458 : updated_(std::move(updated)) {}
460 const std::unordered_map<std::string, std::string>& updated()
const {
return updated_; }
466 Kind
kind()
const override {
return Kind::kSetProperties; }
470 std::unique_ptr<TableUpdate>
Clone()
const override;
473 std::unordered_map<std::string, std::string> updated_;
480 : removed_(std::move(removed)) {}
482 const std::unordered_set<std::string>& removed()
const {
return removed_; }
488 Kind
kind()
const override {
return Kind::kRemoveProperties; }
492 std::unique_ptr<TableUpdate>
Clone()
const override;
495 std::unordered_set<std::string> removed_;
501 explicit SetLocation(std::string location) : location_(std::move(location)) {}
503 const std::string& location()
const {
return location_; }
509 Kind
kind()
const override {
return Kind::kSetLocation; }
513 std::unique_ptr<TableUpdate>
Clone()
const override;
516 std::string location_;
522 explicit SetStatistics(std::shared_ptr<StatisticsFile> statistics_file)
523 : statistics_file_(std::move(statistics_file)) {}
525 int64_t snapshot_id()
const;
527 const std::shared_ptr<StatisticsFile>& statistics_file()
const {
528 return statistics_file_;
535 Kind
kind()
const override {
return Kind::kSetStatistics; }
539 std::unique_ptr<TableUpdate>
Clone()
const override;
542 std::shared_ptr<StatisticsFile> statistics_file_;
548 explicit RemoveStatistics(int64_t snapshot_id) : snapshot_id_(snapshot_id) {}
550 int64_t snapshot_id()
const {
return snapshot_id_; }
556 Kind
kind()
const override {
return Kind::kRemoveStatistics; }
560 std::unique_ptr<TableUpdate>
Clone()
const override;
563 int64_t snapshot_id_;
570 std::shared_ptr<PartitionStatisticsFile> partition_statistics_file)
571 : partition_statistics_file_(std::move(partition_statistics_file)) {}
573 int64_t snapshot_id()
const;
575 const std::shared_ptr<PartitionStatisticsFile>& partition_statistics_file()
const {
576 return partition_statistics_file_;
583 Kind
kind()
const override {
return Kind::kSetPartitionStatistics; }
587 std::unique_ptr<TableUpdate>
Clone()
const override;
590 std::shared_ptr<PartitionStatisticsFile> partition_statistics_file_;
598 int64_t snapshot_id()
const {
return snapshot_id_; }
604 Kind
kind()
const override {
return Kind::kRemovePartitionStatistics; }
608 std::unique_ptr<TableUpdate>
Clone()
const override;
611 int64_t snapshot_id_;
625 Kind
kind()
const override {
return Kind::kAddEncryptionKey; }
629 std::unique_ptr<TableUpdate>
Clone()
const override;
640 const std::string& key_id()
const {
return key_id_; }
646 Kind
kind()
const override {
return Kind::kRemoveEncryptionKey; }
650 std::unique_ptr<TableUpdate>
Clone()
const override;
Context for generating table requirements.
Definition table_requirements.h:45
Base class for metadata update operations.
Definition table_update.h:43
virtual Kind kind() const =0
Return the kind of this update.
friend bool operator==(const TableUpdate &lhs, const TableUpdate &rhs)
Compare two TableUpdate instances for equality.
Definition table_update.h:106
virtual void GenerateRequirements(TableUpdateContext &context) const =0
Generate update requirements for this metadata update.
virtual void ApplyTo(TableMetadataBuilder &builder) const =0
Apply this update to a TableMetadataBuilder.
virtual bool Equals(const TableUpdate &other) const =0
Check equality with another TableUpdate.
virtual std::unique_ptr< TableUpdate > Clone() const =0
Create a deep copy of this update.
Represents adding an encryption key to the table.
Definition table_update.h:615
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:625
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Represents adding a new partition spec to the table.
Definition table_update.h:203
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:214
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Represents adding a new schema to the table.
Definition table_update.h:157
Kind kind() const override
Return the kind of this update.
Definition table_update.h:170
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Represents adding a snapshot to the table.
Definition table_update.h:333
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:344
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Represents adding a new sort order to the table.
Definition table_update.h:290
Kind kind() const override
Return the kind of this update.
Definition table_update.h:301
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Represents an assignment of a UUID to the table.
Definition table_update.h:114
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:124
Represents removing an encryption key from the table.
Definition table_update.h:636
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:646
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Represents removing partition specs from the table.
Definition table_update.h:246
Kind kind() const override
Return the kind of this update.
Definition table_update.h:257
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Represents removing partition statistics for a snapshot.
Definition table_update.h:594
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:604
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Represents removing table properties.
Definition table_update.h:477
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:488
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Represents removing schemas from the table.
Definition table_update.h:268
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:279
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Represents removing a snapshot reference.
Definition table_update.h:377
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:387
Represents removing snapshots from the table.
Definition table_update.h:355
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:366
Represents removing statistics for a snapshot.
Definition table_update.h:546
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:556
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Represents setting the current schema.
Definition table_update.h:182
Kind kind() const override
Return the kind of this update.
Definition table_update.h:192
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Represents setting the default partition spec.
Definition table_update.h:225
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:235
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Represents setting the default sort order.
Definition table_update.h:312
Kind kind() const override
Return the kind of this update.
Definition table_update.h:322
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Represents setting the table location.
Definition table_update.h:499
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:509
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Represents setting partition statistics for a snapshot.
Definition table_update.h:567
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:583
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Represents setting table properties.
Definition table_update.h:455
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:466
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Represents setting a snapshot reference.
Definition table_update.h:398
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:439
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
Represents setting statistics for a snapshot.
Definition table_update.h:520
std::unique_ptr< TableUpdate > Clone() const override
Create a deep copy of this update.
void GenerateRequirements(TableUpdateContext &context) const override
Generate update requirements for this metadata update.
void ApplyTo(TableMetadataBuilder &builder) const override
Apply this update to a TableMetadataBuilder.
Kind kind() const override
Return the kind of this update.
Definition table_update.h:535
bool Equals(const TableUpdate &other) const override
Check equality with another TableUpdate.
ICEBERG_EXPORT const std::shared_ptr< UuidType > & uuid()
Return a UuidType instance.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
SnapshotRefType
The type of snapshot reference.
Definition snapshot.h:43
Define snapshot metadata types.
Represents an encrypted table key entry.
Definition encrypted_key.h:34
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