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


##########
src/iceberg/table_requirement.cc:
##########
@@ -19,43 +19,77 @@
 
 #include "iceberg/table_requirement.h"
 
+#include "iceberg/snapshot.h"
 #include "iceberg/table_metadata.h"
+#include "iceberg/util/macros.h"
 #include "iceberg/util/string_util.h"
 
 namespace iceberg::table {
 
 Status AssertDoesNotExist::Validate(const TableMetadata* base) const {
-  return NotImplemented("AssertDoesNotExist::Validate not implemented");
+  if (base != nullptr) {
+    return CommitFailed("Requirement failed: table already exists");
+  }
+
+  return {};
 }
 
 Status AssertUUID::Validate(const TableMetadata* base) const {
-  // Validate that the table UUID matches the expected value
-
   if (base == nullptr) {
     return CommitFailed("Requirement failed: current table metadata is 
missing");
   }
 
   if (!StringUtils::EqualsIgnoreCase(base->table_uuid, uuid_)) {
     return CommitFailed(
-        "Requirement failed: table UUID does not match (expected='{}', 
actual='{}')",
-        uuid_, base->table_uuid);
+        "Requirement failed: table UUID does not match, expected {} != {}", 
uuid_,
+        base->table_uuid);
   }
 
   return {};
 }
 
 Status AssertRefSnapshotID::Validate(const TableMetadata* base) const {
-  return NotImplemented("AssertTableRefSnapshotID::Validate not implemented");
+  if (base == nullptr) {
+    return CommitFailed("Requirement failed: current table metadata is 
missing");
+  }
+
+  if (auto ref = base->refs.find(ref_name_); ref != base->refs.cend()) {
+    const auto& snapshot_ref = ref->second;
+    ICEBERG_DCHECK(snapshot_ref != nullptr, "Snapshot reference is null");
+    std::string_view type =
+        snapshot_ref->type() == SnapshotRefType::kBranch ? "branch" : "tag";
+    if (!snapshot_id_.has_value()) {
+      // A null snapshot ID means the ref should not exist already
+      return CommitFailed("Requirement failed: {} '{}' was created 
concurrently", type,
+                          ref_name_);
+    } else if (snapshot_id_.value() != snapshot_ref->snapshot_id) {
+      return CommitFailed("Requirement failed: {} '{}' has changed: expected 
id {} != {}",
+                          type, ref_name_, snapshot_id_.value(),
+                          snapshot_ref->snapshot_id);
+    }
+  } else if (snapshot_id_.has_value()) {
+    return CommitFailed("Requirement failed: branch or tag '{}' is missing, 
expected {}",
+                        ref_name_, snapshot_id_.value());
+  }
+
+  return {};
 }
 
 Status AssertLastAssignedFieldId::Validate(const TableMetadata* base) const {
-  return NotImplemented(
-      "AssertCurrentTableLastAssignedFieldId::Validate not implemented");
+  if (base == nullptr) {
+    return CommitFailed("Requirement failed: current table metadata is 
missing");
+  }
+

Review Comment:
   ```suggestion
   ```



-- 
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