2222#include " iceberg/exception.h"
2323#include " iceberg/schema.h"
2424#include " iceberg/sort_order.h"
25+ #include " iceberg/statistics_file.h"
2526#include " iceberg/table_metadata.h"
2627#include " iceberg/table_requirements.h"
28+ #include " iceberg/util/checked_cast.h"
2729
2830namespace iceberg {
2931TableUpdate::~TableUpdate () = default ;
@@ -45,7 +47,7 @@ bool AssignUUID::Equals(const TableUpdate& other) const {
4547 if (other.kind () != Kind::kAssignUUID ) {
4648 return false ;
4749 }
48- const auto & other_assign = static_cast <const AssignUUID&>(other);
50+ const auto & other_assign = internal::checked_cast <const AssignUUID&>(other);
4951 return uuid_ == other_assign.uuid_ ;
5052}
5153
@@ -67,7 +69,7 @@ bool UpgradeFormatVersion::Equals(const TableUpdate& other) const {
6769 if (other.kind () != Kind::kUpgradeFormatVersion ) {
6870 return false ;
6971 }
70- const auto & other_upgrade = static_cast <const UpgradeFormatVersion&>(other);
72+ const auto & other_upgrade = internal::checked_cast <const UpgradeFormatVersion&>(other);
7173 return format_version_ == other_upgrade.format_version_ ;
7274}
7375
@@ -117,7 +119,7 @@ bool SetCurrentSchema::Equals(const TableUpdate& other) const {
117119 if (other.kind () != Kind::kSetCurrentSchema ) {
118120 return false ;
119121 }
120- const auto & other_set = static_cast <const SetCurrentSchema&>(other);
122+ const auto & other_set = internal::checked_cast <const SetCurrentSchema&>(other);
121123 return schema_id_ == other_set.schema_id_ ;
122124}
123125
@@ -167,7 +169,7 @@ bool SetDefaultPartitionSpec::Equals(const TableUpdate& other) const {
167169 if (other.kind () != Kind::kSetDefaultPartitionSpec ) {
168170 return false ;
169171 }
170- const auto & other_set = static_cast <const SetDefaultPartitionSpec&>(other);
172+ const auto & other_set = internal::checked_cast <const SetDefaultPartitionSpec&>(other);
171173 return spec_id_ == other_set.spec_id_ ;
172174}
173175
@@ -190,7 +192,7 @@ bool RemovePartitionSpecs::Equals(const TableUpdate& other) const {
190192 if (other.kind () != Kind::kRemovePartitionSpecs ) {
191193 return false ;
192194 }
193- const auto & other_remove = static_cast <const RemovePartitionSpecs&>(other);
195+ const auto & other_remove = internal::checked_cast <const RemovePartitionSpecs&>(other);
194196 return spec_ids_ == other_remove.spec_ids_ ;
195197}
196198
@@ -213,7 +215,7 @@ bool RemoveSchemas::Equals(const TableUpdate& other) const {
213215 if (other.kind () != Kind::kRemoveSchemas ) {
214216 return false ;
215217 }
216- const auto & other_remove = static_cast <const RemoveSchemas&>(other);
218+ const auto & other_remove = internal::checked_cast <const RemoveSchemas&>(other);
217219 return schema_ids_ == other_remove.schema_ids_ ;
218220}
219221
@@ -263,7 +265,7 @@ bool SetDefaultSortOrder::Equals(const TableUpdate& other) const {
263265 if (other.kind () != Kind::kSetDefaultSortOrder ) {
264266 return false ;
265267 }
266- const auto & other_set = static_cast <const SetDefaultSortOrder&>(other);
268+ const auto & other_set = internal::checked_cast <const SetDefaultSortOrder&>(other);
267269 return sort_order_id_ == other_set.sort_order_id_ ;
268270}
269271
@@ -313,7 +315,7 @@ bool RemoveSnapshots::Equals(const TableUpdate& other) const {
313315 if (other.kind () != Kind::kRemoveSnapshots ) {
314316 return false ;
315317 }
316- const auto & other_remove = static_cast <const RemoveSnapshots&>(other);
318+ const auto & other_remove = internal::checked_cast <const RemoveSnapshots&>(other);
317319 return snapshot_ids_ == other_remove.snapshot_ids_ ;
318320}
319321
@@ -335,7 +337,7 @@ bool RemoveSnapshotRef::Equals(const TableUpdate& other) const {
335337 if (other.kind () != Kind::kRemoveSnapshotRef ) {
336338 return false ;
337339 }
338- const auto & other_remove = static_cast <const RemoveSnapshotRef&>(other);
340+ const auto & other_remove = internal::checked_cast <const RemoveSnapshotRef&>(other);
339341 return ref_name_ == other_remove.ref_name_ ;
340342}
341343
@@ -366,7 +368,7 @@ bool SetSnapshotRef::Equals(const TableUpdate& other) const {
366368 if (other.kind () != Kind::kSetSnapshotRef ) {
367369 return false ;
368370 }
369- const auto & other_set = static_cast <const SetSnapshotRef&>(other);
371+ const auto & other_set = internal::checked_cast <const SetSnapshotRef&>(other);
370372 return ref_name_ == other_set.ref_name_ && snapshot_id_ == other_set.snapshot_id_ &&
371373 type_ == other_set.type_ &&
372374 min_snapshots_to_keep_ == other_set.min_snapshots_to_keep_ &&
@@ -394,7 +396,7 @@ bool SetProperties::Equals(const TableUpdate& other) const {
394396 if (other.kind () != Kind::kSetProperties ) {
395397 return false ;
396398 }
397- const auto & other_set = static_cast <const SetProperties&>(other);
399+ const auto & other_set = internal::checked_cast <const SetProperties&>(other);
398400 return updated_ == other_set.updated_ ;
399401}
400402
@@ -416,7 +418,7 @@ bool RemoveProperties::Equals(const TableUpdate& other) const {
416418 if (other.kind () != Kind::kRemoveProperties ) {
417419 return false ;
418420 }
419- const auto & other_remove = static_cast <const RemoveProperties&>(other);
421+ const auto & other_remove = internal::checked_cast <const RemoveProperties&>(other);
420422 return removed_ == other_remove.removed_ ;
421423}
422424
@@ -438,12 +440,64 @@ bool SetLocation::Equals(const TableUpdate& other) const {
438440 if (other.kind () != Kind::kSetLocation ) {
439441 return false ;
440442 }
441- const auto & other_set = static_cast <const SetLocation&>(other);
443+ const auto & other_set = internal::checked_cast <const SetLocation&>(other);
442444 return location_ == other_set.location_ ;
443445}
444446
445447std::unique_ptr<TableUpdate> SetLocation::Clone () const {
446448 return std::make_unique<SetLocation>(location_);
447449}
448450
451+ // SetStatistics
452+
453+ int64_t SetStatistics::snapshot_id () const { return statistics_file_->snapshot_id ; }
454+
455+ void SetStatistics::ApplyTo (TableMetadataBuilder& builder) const {
456+ builder.SetStatistics (statistics_file_);
457+ }
458+
459+ void SetStatistics::GenerateRequirements (TableUpdateContext& context) const {
460+ // SetStatistics doesn't generate any requirements
461+ }
462+
463+ bool SetStatistics::Equals (const TableUpdate& other) const {
464+ if (other.kind () != Kind::kSetStatistics ) {
465+ return false ;
466+ }
467+ const auto & other_set = internal::checked_cast<const SetStatistics&>(other);
468+ if (!statistics_file_ != !other_set.statistics_file_ ) {
469+ return false ;
470+ }
471+ if (statistics_file_ && !(*statistics_file_ == *other_set.statistics_file_ )) {
472+ return false ;
473+ }
474+ return true ;
475+ }
476+
477+ std::unique_ptr<TableUpdate> SetStatistics::Clone () const {
478+ return std::make_unique<SetStatistics>(statistics_file_);
479+ }
480+
481+ // RemoveStatistics
482+
483+ void RemoveStatistics::ApplyTo (TableMetadataBuilder& builder) const {
484+ builder.RemoveStatistics (snapshot_id_);
485+ }
486+
487+ void RemoveStatistics::GenerateRequirements (TableUpdateContext& context) const {
488+ // RemoveStatistics doesn't generate any requirements
489+ }
490+
491+ bool RemoveStatistics::Equals (const TableUpdate& other) const {
492+ if (other.kind () != Kind::kRemoveStatistics ) {
493+ return false ;
494+ }
495+ const auto & other_remove = internal::checked_cast<const RemoveStatistics&>(other);
496+ return snapshot_id_ == other_remove.snapshot_id_ ;
497+ }
498+
499+ std::unique_ptr<TableUpdate> RemoveStatistics::Clone () const {
500+ return std::make_unique<RemoveStatistics>(snapshot_id_);
501+ }
502+
449503} // namespace iceberg::table
0 commit comments