Skip to content

Commit 2902e76

Browse files
committed
Revert "fix: address PR feedback for table requirement validations"
This reverts commit 6ba8daf.
1 parent 6ba8daf commit 2902e76

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

src/iceberg/table_requirement.cc

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,32 @@ Status AssertRefSnapshotID::Validate(const TableMetadata* base) const {
5555
// Validate that a reference (branch or tag) points to the expected snapshot ID
5656

5757
if (base == nullptr) {
58-
// For new tables (null base), only succeed if we're not expecting a specific snapshot
59-
if (snapshot_id_.has_value()) {
60-
return CommitFailed(
61-
"Requirement failed: branch or tag '{}' is missing, expected {}", ref_name_,
62-
snapshot_id_.value());
63-
}
64-
return {};
58+
return CommitFailed("Requirement failed: current table metadata is missing");
6559
}
6660

6761
auto it = base->refs.find(ref_name_);
68-
if (it != base->refs.end()) {
69-
// Reference exists
70-
if (!snapshot_id_.has_value()) {
71-
// A null snapshot ID means the ref should not exist already
72-
return CommitFailed(
73-
"Requirement failed: reference '{}' was created concurrently", ref_name_);
74-
} else if (snapshot_id_.value() != it->second->snapshot_id) {
62+
63+
// If snapshot_id is nullopt, the reference should not exist
64+
if (!snapshot_id_.has_value()) {
65+
if (it != base->refs.end()) {
7566
return CommitFailed(
76-
"Requirement failed: reference '{}' has changed: expected id {} != {}",
77-
ref_name_, snapshot_id_.value(), it->second->snapshot_id);
67+
"Requirement failed: reference '{}' should not exist but found snapshot ID {}",
68+
ref_name_, it->second->snapshot_id);
7869
}
79-
} else if (snapshot_id_.has_value()) {
80-
// Reference does not exist but snapshot_id is specified
70+
return {};
71+
}
72+
73+
// snapshot_id has a value, so the reference should exist and match
74+
if (it == base->refs.end()) {
75+
return CommitFailed("Requirement failed: reference '{}' is missing in table metadata",
76+
ref_name_);
77+
}
78+
79+
if (it->second->snapshot_id != snapshot_id_.value()) {
8180
return CommitFailed(
82-
"Requirement failed: branch or tag '{}' is missing, expected {}", ref_name_,
83-
snapshot_id_.value());
81+
"Requirement failed: reference '{}' snapshot ID does not match (expected={}, "
82+
"actual={})",
83+
ref_name_, snapshot_id_.value(), it->second->snapshot_id);
8484
}
8585

8686
return {};
@@ -89,7 +89,11 @@ Status AssertRefSnapshotID::Validate(const TableMetadata* base) const {
8989
Status AssertLastAssignedFieldId::Validate(const TableMetadata* base) const {
9090
// Validate that the last assigned field ID matches the expected value
9191

92-
if (base && base->last_column_id != last_assigned_field_id_) {
92+
if (base == nullptr) {
93+
return CommitFailed("Requirement failed: current table metadata is missing");
94+
}
95+
96+
if (base->last_column_id != last_assigned_field_id_) {
9397
return CommitFailed(
9498
"Requirement failed: last assigned field ID does not match (expected={}, "
9599
"actual={})",
@@ -123,7 +127,11 @@ Status AssertCurrentSchemaID::Validate(const TableMetadata* base) const {
123127
Status AssertLastAssignedPartitionId::Validate(const TableMetadata* base) const {
124128
// Validate that the last assigned partition ID matches the expected value
125129

126-
if (base && base->last_partition_id != last_assigned_partition_id_) {
130+
if (base == nullptr) {
131+
return CommitFailed("Requirement failed: current table metadata is missing");
132+
}
133+
134+
if (base->last_partition_id != last_assigned_partition_id_) {
127135
return CommitFailed(
128136
"Requirement failed: last assigned partition ID does not match (expected={}, "
129137
"actual={})",

src/iceberg/test/table_metadata_builder_test.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,23 @@ TEST_F(TableMetadataBuilderTest, TableRequirementAssertRefSnapshotIDMismatch) {
299299

300300
auto status = requirement.Validate(base_metadata_.get());
301301
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
302-
EXPECT_THAT(status, HasErrorMessage("has changed"));
302+
EXPECT_THAT(status, HasErrorMessage("snapshot ID does not match"));
303303
}
304304

305305
TEST_F(TableMetadataBuilderTest, TableRequirementAssertRefSnapshotIDRefMissing) {
306306
table::AssertRefSnapshotID requirement("missing-ref", 100);
307307

308308
auto status = requirement.Validate(base_metadata_.get());
309309
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
310-
EXPECT_THAT(status, HasErrorMessage("is missing"));
310+
EXPECT_THAT(status, HasErrorMessage("missing in table metadata"));
311311
}
312312

313313
TEST_F(TableMetadataBuilderTest, TableRequirementAssertRefSnapshotIDNullBase) {
314314
table::AssertRefSnapshotID requirement("main", 100);
315315

316316
auto status = requirement.Validate(nullptr);
317317
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
318-
EXPECT_THAT(status, HasErrorMessage("is missing"));
318+
EXPECT_THAT(status, HasErrorMessage("metadata is missing"));
319319
}
320320

321321
TEST_F(TableMetadataBuilderTest, TableRequirementAssertRefSnapshotIDNulloptSuccess) {
@@ -336,7 +336,7 @@ TEST_F(TableMetadataBuilderTest, TableRequirementAssertRefSnapshotIDNulloptButEx
336336

337337
auto status = requirement.Validate(base_metadata_.get());
338338
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
339-
EXPECT_THAT(status, HasErrorMessage("created concurrently"));
339+
EXPECT_THAT(status, HasErrorMessage("should not exist"));
340340
}
341341

342342
TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedFieldIdSuccess) {
@@ -358,8 +358,9 @@ TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedFieldIdMismat
358358
TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedFieldIdNullBase) {
359359
table::AssertLastAssignedFieldId requirement(10);
360360

361-
// Null base is allowed (for new tables)
362-
ASSERT_THAT(requirement.Validate(nullptr), IsOk());
361+
auto status = requirement.Validate(nullptr);
362+
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
363+
EXPECT_THAT(status, HasErrorMessage("metadata is missing"));
363364
}
364365

365366
TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedPartitionIdSuccess) {
@@ -381,8 +382,9 @@ TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedPartitionIdMi
381382
TEST_F(TableMetadataBuilderTest, TableRequirementAssertLastAssignedPartitionIdNullBase) {
382383
table::AssertLastAssignedPartitionId requirement(5);
383384

384-
// Null base is allowed (for new tables)
385-
ASSERT_THAT(requirement.Validate(nullptr), IsOk());
385+
auto status = requirement.Validate(nullptr);
386+
EXPECT_THAT(status, IsError(ErrorKind::kCommitFailed));
387+
EXPECT_THAT(status, HasErrorMessage("metadata is missing"));
386388
}
387389

388390
TEST_F(TableMetadataBuilderTest, TableRequirementAssertDefaultSpecIDSuccess) {

0 commit comments

Comments
 (0)