dannycjones commented on code in PR #2773:
URL: https://github.com/apache/iceberg-rust/pull/2773#discussion_r4015323369
##########
crates/iceberg/src/spec/partition.rs:
##########
@@ -103,8 +103,32 @@ impl PartitionSpec {
}
/// Returns the partition type of this partition spec.
+ /// If a source column is absent, preserves fixed transform result types
and uses
+ /// unknown for result types that depend on the source type.
pub fn partition_type(&self, schema: &Schema) -> Result<StructType> {
- PartitionSpecBuilder::partition_type(&self.fields, schema)
+ let mut struct_fields = Vec::with_capacity(self.fields.len());
+ for partition_field in &self.fields {
+ let res_type = match schema.field_by_id(partition_field.source_id)
{
+ Some(field) =>
partition_field.transform.result_type(&field.field_type)?,
+ // Historical specs may reference dropped source columns.
Retain every
+ // field's position and any result type that is independent of
its source.
+ None => match partition_field.transform {
+ Transform::Bucket(_) | Transform::Year | Transform::Month
| Transform::Hour => {
+ PrimitiveType::Int.into()
+ }
+ Transform::Day => PrimitiveType::Date.into(),
+ Transform::Unknown => PrimitiveType::String.into(),
+ Transform::Identity | Transform::Truncate(_) |
Transform::Void => {
+ PrimitiveType::Unknown.into()
+ }
+ },
+ };
+ struct_fields.push(
+ NestedField::optional(partition_field.field_id,
&partition_field.name, res_type)
+ .into(),
+ );
+ }
+ Ok(StructType::new(struct_fields))
}
Review Comment:
This looks like a more general fix, can we address it in a separate PR ahead
of this one?
--
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]