You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ga...@apache.org on 2025/11/04 02:09:00 UTC
(iceberg-cpp) branch main updated: feat: Add validation for AssertCurrentSchemaID (#286)
This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 1a6f9c8 feat: Add validation for AssertCurrentSchemaID (#286)
1a6f9c8 is described below
commit 1a6f9c89ec12d43906c9088ea6779c2e7b874c14
Author: Xinli Shang <xi...@gmail.com>
AuthorDate: Mon Nov 3 18:08:55 2025 -0800
feat: Add validation for AssertCurrentSchemaID (#286)
---
src/iceberg/table_requirement.cc | 19 +++++++++++++-
src/iceberg/test/table_metadata_builder_test.cc | 33 +++++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/iceberg/table_requirement.cc b/src/iceberg/table_requirement.cc
index e951d70..0b8e795 100644
--- a/src/iceberg/table_requirement.cc
+++ b/src/iceberg/table_requirement.cc
@@ -54,7 +54,24 @@ Status AssertLastAssignedFieldId::Validate(const TableMetadata* base) const {
}
Status AssertCurrentSchemaID::Validate(const TableMetadata* base) const {
- return NotImplemented("AssertCurrentTableSchemaID::Validate not implemented");
+ // Validate that the current schema ID matches the one used when the metadata was read
+
+ if (base == nullptr) {
+ return CommitFailed("Requirement failed: current table metadata is missing");
+ }
+
+ if (!base->current_schema_id.has_value()) {
+ return CommitFailed(
+ "Requirement failed: current schema ID is not set in table metadata");
+ }
+
+ if (base->current_schema_id.value() != schema_id_) {
+ return CommitFailed(
+ "Requirement failed: current schema ID does not match (expected={}, actual={})",
+ schema_id_, base->current_schema_id.value());
+ }
+
+ return {};
}
Status AssertLastAssignedPartitionId::Validate(const TableMetadata* base) const {
diff --git a/src/iceberg/test/table_metadata_builder_test.cc b/src/iceberg/test/table_metadata_builder_test.cc
index aa22f85..6b2314f 100644
--- a/src/iceberg/test/table_metadata_builder_test.cc
+++ b/src/iceberg/test/table_metadata_builder_test.cc
@@ -231,6 +231,39 @@ TEST_F(TableMetadataBuilderTest, TableRequirementAssertUUIDCaseInsensitive) {
ASSERT_THAT(requirement.Validate(base_metadata_.get()), IsOk());
}
+TEST_F(TableMetadataBuilderTest, TableRequirementAssertCurrentSchemaIDSuccess) {
+ base_metadata_->current_schema_id = 5;
+ table::AssertCurrentSchemaID requirement(5);
+
+ ASSERT_THAT(requirement.Validate(base_metadata_.get()), IsOk());
+}
+
+TEST_F(TableMetadataBuilderTest, TableRequirementAssertCurrentSchemaIDMismatch) {
+ base_metadata_->current_schema_id = 5;
+ table::AssertCurrentSchemaID requirement(10);
+
+ auto status = requirement.Validate(base_metadata_.get());
+ EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
+ EXPECT_THAT(status, HasErrorMessage("schema ID does not match"));
+}
+
+TEST_F(TableMetadataBuilderTest, TableRequirementAssertCurrentSchemaIDNullBase) {
+ table::AssertCurrentSchemaID requirement(5);
+
+ auto status = requirement.Validate(nullptr);
+ EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
+ EXPECT_THAT(status, HasErrorMessage("metadata is missing"));
+}
+
+TEST_F(TableMetadataBuilderTest, TableRequirementAssertCurrentSchemaIDNotSet) {
+ base_metadata_->current_schema_id = std::nullopt;
+ table::AssertCurrentSchemaID requirement(5);
+
+ auto status = requirement.Validate(base_metadata_.get());
+ EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
+ EXPECT_THAT(status, HasErrorMessage("schema ID is not set"));
+}
+
// ============================================================================
// Integration Tests - End-to-End Workflow
// ============================================================================