-
Notifications
You must be signed in to change notification settings - Fork 75
feat: transactional UpdateProperties method support #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lishuxu
wants to merge
20
commits into
apache:main
Choose a base branch
from
lishuxu:feature/transaction-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+711
−29
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7ed91d9
feat: add table-update api to transaction interface
235b4bc
feat: transactional UpdateProperties support
2d73eb6
feat: transactional UpdateProperties method support
a72ae7a
feat: transactional UpdateProperties method support
18fd9af
feat: transactional UpdateProperties method support
0b5647d
feat: table transactional UpdateProperties support
492bbed
feat: transactional UpdateProperties method support
601bd97
feat: transactional UpdateProperties method support
49734a6
feat: transactional UpdateProperties method support
a88e27b
feat: transactional UpdateProperties method support
cd00a7b
feat: transactional UpdateProperties method support
43c8362
feat: transactional UpdateProperties method support
b1ac478
feat: add update table properties support
93477bf
feat: transactional UpdateProperties method support
eace259
feat: transactional UpdateProperties method support
56802ce
feat: transactional UpdateProperties method support
5efe0e0
feat: transactional UpdateProperties method support
9579da2
feat: transactional UpdateProperties method support
51dbf1f
feat: transactional UpdateProperties method support
df573b4
feat: transactional UpdateProperties method support
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include <unordered_map> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "iceberg/partition_spec.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/table.h" | ||
| #include "iceberg/table_metadata.h" | ||
| #include "iceberg/table_update.h" | ||
| #include "iceberg/test/matchers.h" | ||
| #include "iceberg/test/mock_catalog.h" | ||
| #include "iceberg/transaction.h" | ||
| #include "iceberg/update/update_properties.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| class BaseTransactionTest : public ::testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| // Create catalog and table identifier | ||
| catalog_ = std::make_shared<::testing::NiceMock<MockCatalog>>(); | ||
|
|
||
| identifier_ = TableIdentifier(Namespace({"test"}), "test_table"); | ||
| auto metadata = std::make_shared<TableMetadata>(); | ||
| table_ = | ||
| std::make_shared<Table>(identifier_, std::move(metadata), | ||
| "s3://bucket/table/metadata.json", nullptr, catalog_); | ||
| } | ||
|
|
||
| std::unique_ptr<Transaction> NewTransaction() { | ||
| auto transaction_result = BaseTransaction::Make(table_, catalog_); | ||
| if (!transaction_result.has_value()) { | ||
| ADD_FAILURE() << "Failed to create transaction: " | ||
| << transaction_result.error().message; | ||
| } | ||
| return std::move(transaction_result).value(); | ||
| } | ||
|
|
||
| TableIdentifier identifier_; | ||
| std::shared_ptr<MockCatalog> catalog_; | ||
| std::shared_ptr<Table> table_; | ||
| }; | ||
|
|
||
| TEST_F(BaseTransactionTest, CommitSetPropertiesUsesCatalog) { | ||
| auto transaction = NewTransaction(); | ||
| auto update_properties = transaction->NewUpdateProperties(); | ||
| EXPECT_TRUE(update_properties.has_value()); | ||
| update_properties.value()->Set("new-key", "new-value"); | ||
| EXPECT_THAT(update_properties.value()->Commit(), IsOk()); | ||
|
|
||
| EXPECT_CALL(*catalog_, | ||
| UpdateTable(::testing::Eq(identifier_), ::testing::_, ::testing::_)) | ||
| .WillOnce( | ||
| [](const TableIdentifier& id, | ||
| const std::vector<std::shared_ptr<const TableRequirement>>& /*requirements*/, | ||
| const std::vector<std::shared_ptr<const TableUpdate>>& updates) | ||
| -> Result<std::unique_ptr<Table>> { | ||
| EXPECT_EQ("test_table", id.name); | ||
| EXPECT_EQ(1u, updates.size()); | ||
| const auto* set_update = | ||
| dynamic_cast<const table::SetProperties*>(updates.front().get()); | ||
| EXPECT_NE(set_update, nullptr); | ||
| const auto& updated = set_update->updated(); | ||
| auto it = updated.find("new-key"); | ||
| EXPECT_NE(it, updated.end()); | ||
| EXPECT_EQ("new-value", it->second); | ||
| return {std::unique_ptr<Table>()}; | ||
| }); | ||
|
|
||
| EXPECT_THAT(transaction->CommitTransaction(), IsOk()); | ||
| } | ||
|
|
||
| TEST_F(BaseTransactionTest, RemovePropertiesSkipsMissingKeys) { | ||
| auto transaction = NewTransaction(); | ||
| auto update_properties = transaction->NewUpdateProperties(); | ||
| EXPECT_TRUE(update_properties.has_value()); | ||
| update_properties.value()->Remove("missing").Remove("existing"); | ||
| EXPECT_THAT(update_properties.value()->Commit(), IsOk()); | ||
|
|
||
| EXPECT_CALL(*catalog_, | ||
| UpdateTable(::testing::Eq(identifier_), ::testing::_, ::testing::_)) | ||
| .WillOnce( | ||
| [](const TableIdentifier&, | ||
| const std::vector<std::shared_ptr<const TableRequirement>>& /*requirements*/, | ||
| const std::vector<std::shared_ptr<const TableUpdate>>& updates) | ||
| -> Result<std::unique_ptr<Table>> { | ||
| EXPECT_EQ(1u, updates.size()); | ||
| const auto* remove_update = | ||
| dynamic_cast<const table::RemoveProperties*>(updates.front().get()); | ||
| EXPECT_NE(remove_update, nullptr); | ||
| EXPECT_THAT(remove_update->removed(), | ||
| ::testing::UnorderedElementsAre("missing", "existing")); | ||
| return {std::unique_ptr<Table>()}; | ||
| }); | ||
|
|
||
| EXPECT_THAT(transaction->CommitTransaction(), IsOk()); | ||
| } | ||
|
|
||
| TEST_F(BaseTransactionTest, AggregatesMultiplePendingUpdates) { | ||
| auto transaction = NewTransaction(); | ||
| auto update_properties = transaction->NewUpdateProperties(); | ||
| EXPECT_TRUE(update_properties.has_value()); | ||
| update_properties.value()->Set("new-key", "new-value"); | ||
| EXPECT_THAT(update_properties.value()->Commit(), IsOk()); | ||
| auto remove_properties = transaction->NewUpdateProperties(); | ||
| EXPECT_TRUE(remove_properties.has_value()); | ||
| remove_properties.value()->Remove("existing"); | ||
| EXPECT_THAT(remove_properties.value()->Commit(), IsOk()); | ||
|
|
||
| EXPECT_CALL(*catalog_, | ||
| UpdateTable(::testing::Eq(identifier_), ::testing::_, ::testing::_)) | ||
| .WillOnce( | ||
| [](const TableIdentifier&, | ||
| const std::vector<std::shared_ptr<const TableRequirement>>& /*requirements*/, | ||
| const std::vector<std::shared_ptr<const TableUpdate>>& updates) | ||
| -> Result<std::unique_ptr<Table>> { | ||
| EXPECT_EQ(2u, updates.size()); | ||
|
|
||
| const auto* set_update = | ||
| dynamic_cast<const table::SetProperties*>(updates[0].get()); | ||
| EXPECT_NE(set_update, nullptr); | ||
| const auto& updated = set_update->updated(); | ||
| auto it = updated.find("new-key"); | ||
| EXPECT_NE(it, updated.end()); | ||
| EXPECT_EQ("new-value", it->second); | ||
|
|
||
| const auto* remove_update = | ||
| dynamic_cast<const table::RemoveProperties*>(updates[1].get()); | ||
| EXPECT_NE(remove_update, nullptr); | ||
| EXPECT_THAT(remove_update->removed(), ::testing::ElementsAre("existing")); | ||
|
|
||
| return {std::unique_ptr<Table>()}; | ||
| }); | ||
|
|
||
| EXPECT_THAT(transaction->CommitTransaction(), IsOk()); | ||
| } | ||
|
|
||
| TEST_F(BaseTransactionTest, FailsIfUpdateNotCommitted) { | ||
| auto transaction = NewTransaction(); | ||
| auto update_properties = transaction->NewUpdateProperties(); | ||
| EXPECT_TRUE(update_properties.has_value()); | ||
| update_properties.value()->Set("new-key", "new-value"); | ||
| EXPECT_THAT(transaction->CommitTransaction(), IsError(ErrorKind::kInvalidState)); | ||
| } | ||
|
|
||
| TEST_F(BaseTransactionTest, NewTransactionFailsWithoutCatalog) { | ||
| auto metadata = std::make_shared<TableMetadata>(); | ||
| auto table_without_catalog = | ||
| std::make_shared<Table>(identifier_, std::move(metadata), | ||
| "s3://bucket/table/metadata.json", nullptr, nullptr); | ||
| EXPECT_THAT(table_without_catalog->NewTransaction(), | ||
| IsError(ErrorKind::kInvalidArgument)); | ||
| } | ||
|
|
||
| } // namespace iceberg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used by transaction catalog so it should not appear here.