|
19 | 19 |
|
20 | 20 | #include "iceberg/transaction.h" |
21 | 21 |
|
| 22 | +#include "iceberg/expression/term.h" |
22 | 23 | #include "iceberg/test/matchers.h" |
23 | 24 | #include "iceberg/test/update_test_base.h" |
| 25 | +#include "iceberg/transform.h" |
24 | 26 | #include "iceberg/update/update_properties.h" |
| 27 | +#include "iceberg/update/update_sort_order.h" |
25 | 28 |
|
26 | 29 | namespace iceberg { |
27 | 30 |
|
@@ -57,24 +60,35 @@ TEST_F(TransactionTest, CommitTransactionWithPropertyUpdate) { |
57 | 60 | TEST_F(TransactionTest, MultipleUpdatesInTransaction) { |
58 | 61 | ICEBERG_UNWRAP_OR_FAIL(auto txn, table_->NewTransaction()); |
59 | 62 |
|
60 | | - // First update |
| 63 | + // First update: set property |
61 | 64 | ICEBERG_UNWRAP_OR_FAIL(auto update1, txn->NewUpdateProperties()); |
62 | | - update1->Set("key1", "value1"); |
| 65 | + update1->Set("key1", "value1").Set("key2", "value2"); |
63 | 66 | EXPECT_THAT(update1->Commit(), IsOk()); |
64 | 67 |
|
65 | | - // Second update |
66 | | - ICEBERG_UNWRAP_OR_FAIL(auto update2, txn->NewUpdateProperties()); |
67 | | - update2->Set("key2", "value2"); |
| 68 | + // Second update: update sort order |
| 69 | + ICEBERG_UNWRAP_OR_FAIL(auto update2, txn->NewUpdateSortOrder()); |
| 70 | + auto ref = NamedReference::Make("x").value(); |
| 71 | + auto term = UnboundTransform::Make(std::move(ref), Transform::Identity()).value(); |
| 72 | + update2->AddSortField(std::move(term), SortDirection::kAscending, NullOrder::kFirst); |
68 | 73 | EXPECT_THAT(update2->Commit(), IsOk()); |
69 | 74 |
|
70 | 75 | // Commit transaction |
71 | 76 | ICEBERG_UNWRAP_OR_FAIL(auto updated_table, txn->Commit()); |
72 | 77 |
|
73 | | - // Verify both properties were set |
| 78 | + // Verify properties were set |
74 | 79 | ICEBERG_UNWRAP_OR_FAIL(auto reloaded, catalog_->LoadTable(table_ident_)); |
75 | 80 | const auto& props = reloaded->properties().configs(); |
76 | 81 | EXPECT_EQ(props.at("key1"), "value1"); |
77 | 82 | EXPECT_EQ(props.at("key2"), "value2"); |
| 83 | + |
| 84 | + // Verify sort order was updated |
| 85 | + ICEBERG_UNWRAP_OR_FAIL(auto sort_order, reloaded->sort_order()); |
| 86 | + EXPECT_FALSE(sort_order->is_unsorted()); |
| 87 | + const auto& fields = sort_order->fields(); |
| 88 | + ASSERT_EQ(fields.size(), 1); |
| 89 | + EXPECT_EQ(fields[0].source_id(), 1); // field id for "x" |
| 90 | + EXPECT_EQ(fields[0].direction(), SortDirection::kAscending); |
| 91 | + EXPECT_EQ(fields[0].null_order(), NullOrder::kFirst); |
78 | 92 | } |
79 | 93 |
|
80 | 94 | } // namespace iceberg |
0 commit comments