28#include <unordered_map>
29#include <unordered_set>
32#include "iceberg/iceberg_export.h"
33#include "iceberg/snapshot.h"
44 enum class Kind : uint8_t {
46 kUpgradeFormatVersion,
50 kSetDefaultPartitionSpec,
51 kRemovePartitionSpecs,
64 kSetPartitionStatistics,
65 kRemovePartitionStatistics,
71 virtual Kind
kind()
const = 0;
100 virtual std::unique_ptr<TableUpdate>
Clone()
const = 0;
104 return lhs.Equals(rhs);
115 const std::string&
uuid()
const {
return uuid_; }
121 Kind
kind()
const override {
return Kind::kAssignUUID; }
123 bool Equals(
const TableUpdate& other)
const override;
125 std::unique_ptr<TableUpdate> Clone()
const override;
135 : format_version_(format_version) {}
137 int8_t format_version()
const {
return format_version_; }
143 Kind
kind()
const override {
return Kind::kUpgradeFormatVersion; }
145 bool Equals(
const TableUpdate& other)
const override;
147 std::unique_ptr<TableUpdate> Clone()
const override;
150 int8_t format_version_;
156 explicit AddSchema(std::shared_ptr<Schema> schema, int32_t last_column_id)
157 : schema_(std::move(schema)), last_column_id_(last_column_id) {}
159 const std::shared_ptr<Schema>& schema()
const {
return schema_; }
161 int32_t last_column_id()
const {
return last_column_id_; }
167 Kind
kind()
const override {
return Kind::kAddSchema; }
169 bool Equals(
const TableUpdate& other)
const override;
171 std::unique_ptr<TableUpdate> Clone()
const override;
174 std::shared_ptr<Schema> schema_;
175 int32_t last_column_id_;
183 int32_t schema_id()
const {
return schema_id_; }
189 Kind
kind()
const override {
return Kind::kSetCurrentSchema; }
191 bool Equals(
const TableUpdate& other)
const override;
193 std::unique_ptr<TableUpdate> Clone()
const override;
203 : spec_(std::move(spec)) {}
205 const std::shared_ptr<PartitionSpec>& spec()
const {
return spec_; }
211 Kind
kind()
const override {
return Kind::kAddPartitionSpec; }
213 bool Equals(
const TableUpdate& other)
const override;
215 std::unique_ptr<TableUpdate> Clone()
const override;
218 std::shared_ptr<PartitionSpec> spec_;
226 int32_t spec_id()
const {
return spec_id_; }
232 Kind
kind()
const override {
return Kind::kSetDefaultPartitionSpec; }
234 bool Equals(
const TableUpdate& other)
const override;
236 std::unique_ptr<TableUpdate> Clone()
const override;
246 : spec_ids_(std::move(spec_ids)) {}
248 const std::vector<int32_t>& spec_ids()
const {
return spec_ids_; }
254 Kind
kind()
const override {
return Kind::kRemovePartitionSpecs; }
256 bool Equals(
const TableUpdate& other)
const override;
258 std::unique_ptr<TableUpdate> Clone()
const override;
261 std::vector<int32_t> spec_ids_;
267 explicit RemoveSchemas(std::unordered_set<int32_t> schema_ids)
268 : schema_ids_(std::move(schema_ids)) {}
270 const std::unordered_set<int32_t>& schema_ids()
const {
return schema_ids_; }
276 Kind
kind()
const override {
return Kind::kRemoveSchemas; }
278 bool Equals(
const TableUpdate& other)
const override;
280 std::unique_ptr<TableUpdate> Clone()
const override;
283 std::unordered_set<int32_t> schema_ids_;
289 explicit AddSortOrder(std::shared_ptr<SortOrder> sort_order)
290 : sort_order_(std::move(sort_order)) {}
292 const std::shared_ptr<SortOrder>& sort_order()
const {
return sort_order_; }
298 Kind
kind()
const override {
return Kind::kAddSortOrder; }
300 bool Equals(
const TableUpdate& other)
const override;
302 std::unique_ptr<TableUpdate> Clone()
const override;
305 std::shared_ptr<SortOrder> sort_order_;
313 int32_t sort_order_id()
const {
return sort_order_id_; }
319 Kind
kind()
const override {
return Kind::kSetDefaultSortOrder; }
321 bool Equals(
const TableUpdate& other)
const override;
323 std::unique_ptr<TableUpdate> Clone()
const override;
326 int32_t sort_order_id_;
332 explicit AddSnapshot(std::shared_ptr<Snapshot> snapshot)
333 : snapshot_(std::move(snapshot)) {}
335 const std::shared_ptr<Snapshot>& snapshot()
const {
return snapshot_; }
341 Kind
kind()
const override {
return Kind::kAddSnapshot; }
343 bool Equals(
const TableUpdate& other)
const override;
345 std::unique_ptr<TableUpdate> Clone()
const override;
348 std::shared_ptr<Snapshot> snapshot_;
355 : snapshot_ids_(std::move(snapshot_ids)) {}
357 const std::vector<int64_t>& snapshot_ids()
const {
return snapshot_ids_; }
363 Kind
kind()
const override {
return Kind::kRemoveSnapshots; }
365 bool Equals(
const TableUpdate& other)
const override;
367 std::unique_ptr<TableUpdate> Clone()
const override;
370 std::vector<int64_t> snapshot_ids_;
376 explicit RemoveSnapshotRef(std::string ref_name) : ref_name_(std::move(ref_name)) {}
378 const std::string& ref_name()
const {
return ref_name_; }
384 Kind
kind()
const override {
return Kind::kRemoveSnapshotRef; }
386 bool Equals(
const TableUpdate& other)
const override;
388 std::unique_ptr<TableUpdate> Clone()
const override;
391 std::string ref_name_;
397 SetSnapshotRef(std::string ref_name, int64_t snapshot_id, SnapshotRefType type,
398 std::optional<int32_t> min_snapshots_to_keep = std::nullopt,
399 std::optional<int64_t> max_snapshot_age_ms = std::nullopt,
400 std::optional<int64_t> max_ref_age_ms = std::nullopt)
401 : ref_name_(std::move(ref_name)),
402 snapshot_id_(snapshot_id),
404 min_snapshots_to_keep_(min_snapshots_to_keep),
405 max_snapshot_age_ms_(max_snapshot_age_ms),
406 max_ref_age_ms_(max_ref_age_ms) {}
409 : ref_name_(std::move(ref_name)), snapshot_id_(ref.snapshot_id), type_(ref.type()) {
410 if (type_ == SnapshotRefType::kBranch) {
411 const auto& branch = std::get<SnapshotRef::Branch>(ref.retention);
412 min_snapshots_to_keep_ = branch.min_snapshots_to_keep;
413 max_snapshot_age_ms_ = branch.max_snapshot_age_ms;
414 max_ref_age_ms_ = branch.max_ref_age_ms;
416 const auto& tag = std::get<SnapshotRef::Tag>(ref.retention);
417 max_ref_age_ms_ = tag.max_ref_age_ms;
421 const std::string& ref_name()
const {
return ref_name_; }
422 int64_t snapshot_id()
const {
return snapshot_id_; }
423 SnapshotRefType type()
const {
return type_; }
424 const std::optional<int32_t>& min_snapshots_to_keep()
const {
425 return min_snapshots_to_keep_;
427 const std::optional<int64_t>& max_snapshot_age_ms()
const {
428 return max_snapshot_age_ms_;
430 const std::optional<int64_t>& max_ref_age_ms()
const {
return max_ref_age_ms_; }
436 Kind
kind()
const override {
return Kind::kSetSnapshotRef; }
438 bool Equals(
const TableUpdate& other)
const override;
440 std::unique_ptr<TableUpdate> Clone()
const override;
443 std::string ref_name_;
444 int64_t snapshot_id_;
445 SnapshotRefType type_;
446 std::optional<int32_t> min_snapshots_to_keep_;
447 std::optional<int64_t> max_snapshot_age_ms_;
448 std::optional<int64_t> max_ref_age_ms_;
454 explicit SetProperties(std::unordered_map<std::string, std::string> updated)
455 : updated_(std::move(updated)) {}
457 const std::unordered_map<std::string, std::string>& updated()
const {
return updated_; }
463 Kind
kind()
const override {
return Kind::kSetProperties; }
465 bool Equals(
const TableUpdate& other)
const override;
467 std::unique_ptr<TableUpdate> Clone()
const override;
470 std::unordered_map<std::string, std::string> updated_;
477 : removed_(std::move(removed)) {}
479 const std::unordered_set<std::string>& removed()
const {
return removed_; }
485 Kind
kind()
const override {
return Kind::kRemoveProperties; }
487 bool Equals(
const TableUpdate& other)
const override;
489 std::unique_ptr<TableUpdate> Clone()
const override;
492 std::unordered_set<std::string> removed_;
498 explicit SetLocation(std::string location) : location_(std::move(location)) {}
500 const std::string& location()
const {
return location_; }
506 Kind
kind()
const override {
return Kind::kSetLocation; }
508 bool Equals(
const TableUpdate& other)
const override;
510 std::unique_ptr<TableUpdate> Clone()
const override;
513 std::string location_;
519 explicit SetStatistics(std::shared_ptr<StatisticsFile> statistics_file)
520 : statistics_file_(std::move(statistics_file)) {}
522 int64_t snapshot_id()
const;
524 const std::shared_ptr<StatisticsFile>& statistics_file()
const {
525 return statistics_file_;
532 Kind
kind()
const override {
return Kind::kSetStatistics; }
534 bool Equals(
const TableUpdate& other)
const override;
536 std::unique_ptr<TableUpdate> Clone()
const override;
539 std::shared_ptr<StatisticsFile> statistics_file_;
545 explicit RemoveStatistics(int64_t snapshot_id) : snapshot_id_(snapshot_id) {}
547 int64_t snapshot_id()
const {
return snapshot_id_; }
553 Kind
kind()
const override {
return Kind::kRemoveStatistics; }
555 bool Equals(
const TableUpdate& other)
const override;
557 std::unique_ptr<TableUpdate> Clone()
const override;
560 int64_t snapshot_id_;
567 std::shared_ptr<PartitionStatisticsFile> partition_statistics_file)
568 : partition_statistics_file_(std::move(partition_statistics_file)) {}
570 int64_t snapshot_id()
const;
572 const std::shared_ptr<PartitionStatisticsFile>& partition_statistics_file()
const {
573 return partition_statistics_file_;
580 Kind
kind()
const override {
return Kind::kSetPartitionStatistics; }
582 bool Equals(
const TableUpdate& other)
const override;
584 std::unique_ptr<TableUpdate> Clone()
const override;
587 std::shared_ptr<PartitionStatisticsFile> partition_statistics_file_;
595 int64_t snapshot_id()
const {
return snapshot_id_; }
601 Kind
kind()
const override {
return Kind::kRemovePartitionStatistics; }
603 bool Equals(
const TableUpdate& other)
const override;
605 std::unique_ptr<TableUpdate> Clone()
const override;
608 int64_t snapshot_id_;
Context for generating table requirements.
Definition table_requirements.h:45
Base class for metadata update operations.
Definition table_update.h:42
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:103
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 a new partition spec to the table.
Definition table_update.h:200
Kind kind() const override
Return the kind of this update.
Definition table_update.h:211
Represents adding a new schema to the table.
Definition table_update.h:154
Kind kind() const override
Return the kind of this update.
Definition table_update.h:167
Represents adding a snapshot to the table.
Definition table_update.h:330
Kind kind() const override
Return the kind of this update.
Definition table_update.h:341
Represents adding a new sort order to the table.
Definition table_update.h:287
Kind kind() const override
Return the kind of this update.
Definition table_update.h:298
Represents an assignment of a UUID to the table.
Definition table_update.h:111
Kind kind() const override
Return the kind of this update.
Definition table_update.h:121
Represents removing partition specs from the table.
Definition table_update.h:243
Kind kind() const override
Return the kind of this update.
Definition table_update.h:254
Represents removing partition statistics for a snapshot.
Definition table_update.h:591
Kind kind() const override
Return the kind of this update.
Definition table_update.h:601
Represents removing table properties.
Definition table_update.h:474
Kind kind() const override
Return the kind of this update.
Definition table_update.h:485
Represents removing schemas from the table.
Definition table_update.h:265
Kind kind() const override
Return the kind of this update.
Definition table_update.h:276
Represents removing a snapshot reference.
Definition table_update.h:374
Kind kind() const override
Return the kind of this update.
Definition table_update.h:384
Represents removing snapshots from the table.
Definition table_update.h:352
Kind kind() const override
Return the kind of this update.
Definition table_update.h:363
Represents removing statistics for a snapshot.
Definition table_update.h:543
Kind kind() const override
Return the kind of this update.
Definition table_update.h:553
Represents setting the current schema.
Definition table_update.h:179
Kind kind() const override
Return the kind of this update.
Definition table_update.h:189
Represents setting the default partition spec.
Definition table_update.h:222
Kind kind() const override
Return the kind of this update.
Definition table_update.h:232
Represents setting the default sort order.
Definition table_update.h:309
Kind kind() const override
Return the kind of this update.
Definition table_update.h:319
Represents setting the table location.
Definition table_update.h:496
Kind kind() const override
Return the kind of this update.
Definition table_update.h:506
Represents setting partition statistics for a snapshot.
Definition table_update.h:564
Kind kind() const override
Return the kind of this update.
Definition table_update.h:580
Represents setting table properties.
Definition table_update.h:452
Kind kind() const override
Return the kind of this update.
Definition table_update.h:463
Represents setting a snapshot reference.
Definition table_update.h:395
Kind kind() const override
Return the kind of this update.
Definition table_update.h:436
Represents setting statistics for a snapshot.
Definition table_update.h:517
Kind kind() const override
Return the kind of this update.
Definition table_update.h:532
ICEBERG_EXPORT const std::shared_ptr< UuidType > & uuid()
Return a UuidType instance.
A reference to a snapshot, either a branch or a tag.
Definition snapshot.h:68