Skip to content

Commit 56802ce

Browse files
author
shuxu.li
committed
feat: transactional UpdateProperties method support
1 parent eace259 commit 56802ce

File tree

9 files changed

+127
-248
lines changed

9 files changed

+127
-248
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
1919
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>")
2020
set(ICEBERG_SOURCES
2121
arrow_c_data_guard_internal.cc
22-
base_transaction.cc
2322
catalog/memory/in_memory_catalog.cc
2423
expression/aggregate.cc
2524
expression/binder.cc
@@ -73,6 +72,7 @@ set(ICEBERG_SOURCES
7372
table_requirements.cc
7473
table_scan.cc
7574
table_update.cc
75+
transaction.cc
7676
transaction_catalog.cc
7777
transform.cc
7878
transform_function.cc

src/iceberg/base_transaction.cc

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/iceberg/base_transaction.h

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/iceberg/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ configure_file(
4141
iceberg_include_dir = include_directories('..')
4242
iceberg_sources = files(
4343
'arrow_c_data_guard_internal.cc',
44-
'base_transaction.cc',
4544
'catalog/memory/in_memory_catalog.cc',
4645
'expression/aggregate.cc',
4746
'expression/binder.cc',
@@ -95,6 +94,7 @@ iceberg_sources = files(
9594
'table_requirements.cc',
9695
'table_scan.cc',
9796
'table_update.cc',
97+
'transaction.cc',
9898
'transaction_catalog.cc',
9999
'transform.cc',
100100
'transform_function.cc',

src/iceberg/table.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
#include "iceberg/table.h"
2121

22-
#include "iceberg/base_transaction.h"
2322
#include "iceberg/catalog.h"
2423
#include "iceberg/partition_spec.h"
2524
#include "iceberg/schema.h"
2625
#include "iceberg/sort_order.h"
2726
#include "iceberg/table_metadata.h"
2827
#include "iceberg/table_properties.h"
2928
#include "iceberg/table_scan.h"
29+
#include "iceberg/transaction.h"
3030
#include "iceberg/update/update_properties.h"
3131
#include "iceberg/util/macros.h"
3232

@@ -114,8 +114,8 @@ std::unique_ptr<UpdateProperties> Table::UpdateProperties() const {
114114
return std::make_unique<iceberg::UpdateProperties>(identifier_, catalog_, metadata_);
115115
}
116116

117-
std::unique_ptr<Transaction> Table::NewTransaction() const {
118-
return std::make_unique<BaseTransaction>(shared_from_this(), catalog_);
117+
Result<std::unique_ptr<Transaction>> Table::NewTransaction() const {
118+
return Transaction::Make(shared_from_this(), catalog_);
119119
}
120120

121121
const std::shared_ptr<FileIO>& Table::io() const { return io_; }

src/iceberg/table.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <vector>
2727

2828
#include "iceberg/iceberg_export.h"
29+
#include "iceberg/result.h"
2930
#include "iceberg/snapshot.h"
3031
#include "iceberg/table_identifier.h"
3132
#include "iceberg/type_fwd.h"
@@ -121,8 +122,8 @@ class ICEBERG_EXPORT Table : public std::enable_shared_from_this<Table> {
121122

122123
/// \brief Create a new transaction for this table
123124
///
124-
/// \return a pointer to the new Transaction
125-
virtual std::unique_ptr<Transaction> NewTransaction() const;
125+
/// \return a new Transaction or an error if the transaction cannot be created
126+
virtual Result<std::unique_ptr<Transaction>> NewTransaction() const;
126127

127128
/// \brief Returns a FileIO to read and write table data and metadata files
128129
const std::shared_ptr<FileIO>& io() const;

src/iceberg/test/base_transaction_test.cc

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
#include "iceberg/base_transaction.h"
21-
2220
#include <unordered_map>
2321

2422
#include <gtest/gtest.h>
@@ -30,6 +28,7 @@
3028
#include "iceberg/table_update.h"
3129
#include "iceberg/test/matchers.h"
3230
#include "iceberg/test/mock_catalog.h"
31+
#include "iceberg/transaction.h"
3332
#include "iceberg/update/update_properties.h"
3433

3534
namespace iceberg {
@@ -47,13 +46,22 @@ class BaseTransactionTest : public ::testing::Test {
4746
"s3://bucket/table/metadata.json", nullptr, catalog_);
4847
}
4948

49+
std::unique_ptr<Transaction> NewTransaction() {
50+
auto transaction_result = BaseTransaction::Make(table_, catalog_);
51+
if (!transaction_result.has_value()) {
52+
ADD_FAILURE() << "Failed to create transaction: "
53+
<< transaction_result.error().message;
54+
}
55+
return std::move(transaction_result).value();
56+
}
57+
5058
TableIdentifier identifier_;
5159
std::shared_ptr<MockCatalog> catalog_;
5260
std::shared_ptr<Table> table_;
5361
};
5462

5563
TEST_F(BaseTransactionTest, CommitSetPropertiesUsesCatalog) {
56-
auto transaction = table_->NewTransaction();
64+
auto transaction = NewTransaction();
5765
auto update_properties = transaction->NewUpdateProperties();
5866
EXPECT_TRUE(update_properties.has_value());
5967
update_properties.value()->Set("new-key", "new-value");
@@ -82,7 +90,7 @@ TEST_F(BaseTransactionTest, CommitSetPropertiesUsesCatalog) {
8290
}
8391

8492
TEST_F(BaseTransactionTest, RemovePropertiesSkipsMissingKeys) {
85-
auto transaction = table_->NewTransaction();
93+
auto transaction = NewTransaction();
8694
auto update_properties = transaction->NewUpdateProperties();
8795
EXPECT_TRUE(update_properties.has_value());
8896
update_properties.value()->Remove("missing").Remove("existing");
@@ -108,7 +116,7 @@ TEST_F(BaseTransactionTest, RemovePropertiesSkipsMissingKeys) {
108116
}
109117

110118
TEST_F(BaseTransactionTest, AggregatesMultiplePendingUpdates) {
111-
auto transaction = table_->NewTransaction();
119+
auto transaction = NewTransaction();
112120
auto update_properties = transaction->NewUpdateProperties();
113121
EXPECT_TRUE(update_properties.has_value());
114122
update_properties.value()->Set("new-key", "new-value");
@@ -147,11 +155,20 @@ TEST_F(BaseTransactionTest, AggregatesMultiplePendingUpdates) {
147155
}
148156

149157
TEST_F(BaseTransactionTest, FailsIfUpdateNotCommitted) {
150-
auto transaction = table_->NewTransaction();
158+
auto transaction = NewTransaction();
151159
auto update_properties = transaction->NewUpdateProperties();
152160
EXPECT_TRUE(update_properties.has_value());
153161
update_properties.value()->Set("new-key", "new-value");
154162
EXPECT_THAT(transaction->CommitTransaction(), IsError(ErrorKind::kInvalidState));
155163
}
156164

165+
TEST_F(BaseTransactionTest, NewTransactionFailsWithoutCatalog) {
166+
auto metadata = std::make_shared<TableMetadata>();
167+
auto table_without_catalog =
168+
std::make_shared<Table>(identifier_, std::move(metadata),
169+
"s3://bucket/table/metadata.json", nullptr, nullptr);
170+
EXPECT_THAT(table_without_catalog->NewTransaction(),
171+
IsError(ErrorKind::kInvalidArgument));
172+
}
173+
157174
} // namespace iceberg

0 commit comments

Comments
 (0)