Skip to content

Commit a6cdea4

Browse files
authored
refactor: simplify UpdateSortOrder::Apply() return type (#436)
1 parent f43d24b commit a6cdea4

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

src/iceberg/test/update_sort_order_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ class UpdateSortOrderTest : public UpdateTestBase {
4444
ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply());
4545
ICEBERG_UNWRAP_OR_FAIL(
4646
auto expected_sort_order,
47-
SortOrder::Make(result.sort_order->order_id(), std::move(expected_fields)));
48-
EXPECT_EQ(*result.sort_order, *expected_sort_order);
47+
SortOrder::Make(result->order_id(), std::move(expected_fields)));
48+
EXPECT_EQ(*result, *expected_sort_order);
4949
}
5050
};
5151

5252
TEST_F(UpdateSortOrderTest, EmptySortOrder) {
5353
ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewUpdateSortOrder());
5454
ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply());
5555
// Should succeed with an unsorted order
56-
EXPECT_TRUE(result.sort_order->fields().empty());
56+
EXPECT_TRUE(result->fields().empty());
5757
}
5858

5959
TEST_F(UpdateSortOrderTest, AddSingleSortFieldAscending) {

src/iceberg/transaction.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ Status Transaction::Apply(PendingUpdate& update) {
8282
} break;
8383
case PendingUpdate::Kind::kUpdateSortOrder: {
8484
auto& update_sort_order = internal::checked_cast<UpdateSortOrder&>(update);
85-
ICEBERG_ASSIGN_OR_RAISE(auto result, update_sort_order.Apply());
86-
metadata_builder_->SetDefaultSortOrder(result.sort_order);
85+
ICEBERG_ASSIGN_OR_RAISE(auto sort_order, update_sort_order.Apply());
86+
metadata_builder_->SetDefaultSortOrder(std::move(sort_order));
8787
} break;
8888
default:
8989
return NotSupported("Unsupported pending update: {}",

src/iceberg/update/update_sort_order.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ UpdateSortOrder& UpdateSortOrder::CaseSensitive(bool case_sensitive) {
8787
return *this;
8888
}
8989

90-
Result<UpdateSortOrder::ApplyResult> UpdateSortOrder::Apply() {
90+
Result<std::shared_ptr<SortOrder>> UpdateSortOrder::Apply() {
9191
ICEBERG_RETURN_UNEXPECTED(CheckErrors());
9292

9393
// If no sort fields are specified, return an unsorted order (ID = 0).
@@ -102,7 +102,7 @@ Result<UpdateSortOrder::ApplyResult> UpdateSortOrder::Apply() {
102102
ICEBERG_ASSIGN_OR_RAISE(auto schema, transaction_->current().Schema());
103103
ICEBERG_RETURN_UNEXPECTED(order->Validate(*schema));
104104
}
105-
return ApplyResult{std::move(order)};
105+
return order;
106106
}
107107

108108
} // namespace iceberg

src/iceberg/update/update_sort_order.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class ICEBERG_EXPORT UpdateSortOrder : public PendingUpdate {
4141

4242
~UpdateSortOrder() override;
4343

44-
struct ApplyResult {
45-
std::shared_ptr<SortOrder> sort_order;
46-
};
47-
4844
/// \brief Add a sort field to the sort order.
4945
///
5046
/// \param term A transform term referencing the field
@@ -72,7 +68,7 @@ class ICEBERG_EXPORT UpdateSortOrder : public PendingUpdate {
7268
Kind kind() const final { return Kind::kUpdateSortOrder; }
7369

7470
/// \brief Apply the pending changes and return the new SortOrder.
75-
Result<ApplyResult> Apply();
71+
Result<std::shared_ptr<SortOrder>> Apply();
7672

7773
private:
7874
explicit UpdateSortOrder(std::shared_ptr<Transaction> transaction);

0 commit comments

Comments
 (0)