File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed
Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -483,14 +483,13 @@ Result<int32_t> TableMetadataBuilder::AddSortOrderInternal(
483483 if (impl_->sort_orders_by_id .find (new_order_id) != impl_->sort_orders_by_id .end ()) {
484484 // update last_added_order_id if the order was added in this set of changes (since it
485485 // is now the last)
486- bool is_new_order = false ;
487- for (const auto & change : impl_->changes ) {
488- auto * add_sort_order = dynamic_cast <table::AddSortOrder*>(change.get ());
489- if (add_sort_order && add_sort_order->sort_order ()->order_id () == new_order_id) {
490- is_new_order = true ;
491- break ;
492- }
493- }
486+ bool is_new_order =
487+ impl_->last_added_order_id .has_value () &&
488+ std::ranges::find_if (impl_->changes , [new_order_id](const auto & change) {
489+ auto * add_sort_order = dynamic_cast <table::AddSortOrder*>(change.get ());
490+ return add_sort_order &&
491+ add_sort_order->sort_order ()->order_id () == new_order_id;
492+ }) != impl_->changes .cend ();
494493 impl_->last_added_order_id =
495494 is_new_order ? std::make_optional (new_order_id) : std::nullopt ;
496495 return new_order_id;
Original file line number Diff line number Diff line change @@ -123,11 +123,18 @@ Status AddSortOrder::GenerateRequirements(TableUpdateContext& context) const {
123123// SetDefaultSortOrder
124124
125125void SetDefaultSortOrder::ApplyTo (TableMetadataBuilder& builder) const {
126- throw IcebergError ( std::format ( " {} not implemented " , __FUNCTION__) );
126+ builder. SetDefaultSortOrder (sort_order_id_ );
127127}
128128
129129Status SetDefaultSortOrder::GenerateRequirements (TableUpdateContext& context) const {
130- return NotImplemented (" SetDefaultTableSortOrder::GenerateRequirements not implemented" );
130+ const TableMetadata* base = context.base ();
131+ if (base != nullptr && !context.is_replace ()) {
132+ context.AddRequirement (
133+ // For table updates, assert that the current default sort order ID matches what
134+ // we expect
135+ std::make_unique<AssertDefaultSortOrderID>(base->default_sort_order_id ));
136+ }
137+ return {};
131138}
132139
133140// AddSnapshot
You can’t perform that action at this time.
0 commit comments