c-thiel commented on code in PR #689:
URL: https://github.com/apache/iceberg-rust/pull/689#discussion_r1834644947


##########
crates/iceberg/src/catalog/mod.rs:
##########
@@ -453,6 +453,115 @@ impl TableUpdate {
     }
 }
 
+impl TableRequirement {
+    /// Check that the requirement is met by the table metadata.
+    /// If the requirement is not met, an appropriate error is returned.
+    pub fn check(&self, metadata: &TableMetadata, exists: bool) -> Result<()> {
+        match self {
+            TableRequirement::NotExist => {
+                if exists {
+                    return Err(Error::new(
+                        ErrorKind::RequirementFailed,
+                        format!("Table with id {} already exists", 
metadata.uuid()),
+                    ));
+                }
+            }
+            TableRequirement::UuidMatch { uuid } => {
+                if &metadata.uuid() != uuid {
+                    return Err(Error::new(
+                        ErrorKind::RequirementFailed,
+                        "Table UUID does not match",
+                    )
+                    .with_context("expected", *uuid)
+                    .with_context("found", metadata.uuid()));
+                }
+            }
+            TableRequirement::CurrentSchemaIdMatch { current_schema_id } => {
+                // ToDo: Harmonize the types of current_schema_id
+                if metadata.current_schema_id != *current_schema_id {
+                    return Err(Error::new(
+                        ErrorKind::RequirementFailed,
+                        "Current schema id does not match",
+                    )
+                    .with_context("expected", current_schema_id.to_string())

Review Comment:
   The signature of .with_context is:
   ` pub fn with_context(mut self, key: &'static str, value: impl Into<String>)`
   
   the trait bound `std::string::String: From<i32>` (also &i32) is not 
satisfied.
   
   Also for the others.
   Should we make `.with_context` more permissive?



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to