c-thiel commented on code in PR #689: URL: https://github.com/apache/iceberg-rust/pull/689#discussion_r1834645951
########## 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()) + .with_context("found", metadata.current_schema_id.to_string())); Review Comment: Ditto ;) ########## 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()) + .with_context("found", metadata.current_schema_id.to_string())); + } + } + TableRequirement::DefaultSortOrderIdMatch { + default_sort_order_id, + } => { + if metadata.default_sort_order().order_id != *default_sort_order_id { + return Err(Error::new( + ErrorKind::RequirementFailed, + "Default sort order id does not match", + ) + .with_context("expected", default_sort_order_id.to_string()) Review Comment: Ditto ;) ########## 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()) + .with_context("found", metadata.current_schema_id.to_string())); + } + } + TableRequirement::DefaultSortOrderIdMatch { + default_sort_order_id, + } => { + if metadata.default_sort_order().order_id != *default_sort_order_id { + return Err(Error::new( + ErrorKind::RequirementFailed, + "Default sort order id does not match", + ) + .with_context("expected", default_sort_order_id.to_string()) + .with_context("found", metadata.default_sort_order().order_id.to_string())); Review Comment: Ditto ;) -- 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