shangxinli commented on code in PR #294:
URL: https://github.com/apache/iceberg-cpp/pull/294#discussion_r2511541980


##########
src/iceberg/table_requirement.cc:
##########
@@ -45,12 +52,55 @@ Status AssertUUID::Validate(const TableMetadata* base) 
const {
 }
 
 Status AssertRefSnapshotID::Validate(const TableMetadata* base) const {
-  return NotImplemented("AssertTableRefSnapshotID::Validate not implemented");
+  // Validate that a reference (branch or tag) points to the expected snapshot 
ID
+
+  if (base == nullptr) {
+    return CommitFailed("Requirement failed: current table metadata is 
missing");
+  }
+
+  auto it = base->refs.find(ref_name_);
+
+  // If snapshot_id is nullopt, the reference should not exist
+  if (!snapshot_id_.has_value()) {
+    if (it != base->refs.end()) {
+      return CommitFailed(
+          "Requirement failed: reference '{}' should not exist but found 
snapshot ID {}",
+          ref_name_, it->second->snapshot_id);
+    }
+    return {};
+  }
+
+  // snapshot_id has a value, so the reference should exist and match
+  if (it == base->refs.end()) {
+    return CommitFailed("Requirement failed: reference '{}' is missing in 
table metadata",
+                        ref_name_);
+  }
+
+  if (it->second->snapshot_id != snapshot_id_.value()) {
+    return CommitFailed(
+        "Requirement failed: reference '{}' snapshot ID does not match 
(expected={}, "
+        "actual={})",
+        ref_name_, snapshot_id_.value(), it->second->snapshot_id);
+  }
+
+  return {};
 }
 
 Status AssertLastAssignedFieldId::Validate(const TableMetadata* base) const {
-  return NotImplemented(
-      "AssertCurrentTableLastAssignedFieldId::Validate not implemented");
+  // Validate that the last assigned field ID matches the expected value
+
+  if (base == nullptr) {
+    return CommitFailed("Requirement failed: current table metadata is 
missing");
+  }
+
+  if (base->last_column_id != last_assigned_field_id_) {

Review Comment:
   Good catch



##########
src/iceberg/table_requirement.cc:
##########
@@ -75,16 +125,53 @@ Status AssertCurrentSchemaID::Validate(const 
TableMetadata* base) const {
 }
 
 Status AssertLastAssignedPartitionId::Validate(const TableMetadata* base) 
const {
-  return NotImplemented(
-      "AssertCurrentTableLastAssignedPartitionId::Validate not implemented");
+  // Validate that the last assigned partition ID matches the expected value
+
+  if (base == nullptr) {
+    return CommitFailed("Requirement failed: current table metadata is 
missing");
+  }
+
+  if (base->last_partition_id != last_assigned_partition_id_) {

Review Comment:
   changed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to