Fokko commented on code in PR #780: URL: https://github.com/apache/iceberg-rust/pull/780#discussion_r1893897923
########## crates/iceberg/src/spec/partition.rs: ########## @@ -69,6 +70,44 @@ pub struct BoundPartitionSpec { partition_type: StructType, } +impl<'de> Deserialize<'de> for BoundPartitionSpec { + fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error> + where D: Deserializer<'de> { + #[derive(Deserialize)] + struct RawBoundPartitionSpec { + spec_id: i32, + fields: Vec<PartitionField>, + schema: SchemaRef, + partition_type: StructType, + } + + let raw_spec = RawBoundPartitionSpec::deserialize(deserializer)?; + + for field in &raw_spec.fields { + let field_type = raw_spec + .schema + .field_by_id(field.source_id) + .ok_or_else(|| serde::de::Error::custom("Invalid value"))? + .field_type + .clone(); + + if !field_type.is_primitive() { + return Err(serde::de::Error::invalid_type( + Unexpected::Other("non-primitive field type"), Review Comment: Can we help the user here by adding the source-id to the error? ```suggestion Unexpected::Other("non-primitive field type"), ``` ########## crates/iceberg/src/spec/partition.rs: ########## @@ -69,6 +70,44 @@ pub struct BoundPartitionSpec { partition_type: StructType, } +impl<'de> Deserialize<'de> for BoundPartitionSpec { + fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error> + where D: Deserializer<'de> { + #[derive(Deserialize)] + struct RawBoundPartitionSpec { + spec_id: i32, + fields: Vec<PartitionField>, + schema: SchemaRef, + partition_type: StructType, + } + + let raw_spec = RawBoundPartitionSpec::deserialize(deserializer)?; + + for field in &raw_spec.fields { + let field_type = raw_spec + .schema + .field_by_id(field.source_id) + .ok_or_else(|| serde::de::Error::custom("Invalid value"))? Review Comment: Same here, can we add the field-id that cannot be found? ```suggestion .ok_or_else(|| serde::de::Error::custom("Invalid value"))? ``` -- 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