mbutrovich commented on code in PR #2188:
URL: https://github.com/apache/iceberg-rust/pull/2188#discussion_r3326680627


##########
crates/iceberg/src/spec/datatypes.rs:
##########
@@ -178,6 +187,17 @@ impl Type {
             Type::Primitive(PrimitiveType::Float) | 
Type::Primitive(PrimitiveType::Double)
         )
     }
+
+    /// Returns the minimum format version required for the type.
+    #[inline(always)]
+    pub fn min_format_version(&self) -> FormatVersion {

Review Comment:
   This currently doesn't recurse: `Type::Struct(...).min_format_version()` 
returns `V1` even if the struct contains a Variant or `TimestampNs`. It happens 
to give the right answer at the schema level only because 
`Schema::min_format_version` iterates `id_to_field.values()`, which already 
includes every nested field as its own entry.
   
   A `SchemaVisitor` would fit the codebase's pattern (the PR already extends 
visitors in seven places) and make the per-`Type` method correct for any input. 
Roughly:
   
   ```rust
   struct MinFormatVersionVisitor;
   impl SchemaVisitor for MinFormatVersionVisitor {
       type T = FormatVersion;
       fn schema(&mut self, _: &Schema, v: FormatVersion) -> 
Result<FormatVersion> { Ok(v) }
       fn field(&mut self, _: &NestedFieldRef, v: FormatVersion) -> 
Result<FormatVersion> { Ok(v) }
       fn r#struct(&mut self, _: &StructType, results: Vec<FormatVersion>) -> 
Result<FormatVersion> {
           Ok(results.into_iter().max().unwrap_or(FormatVersion::V1))
       }
       fn list(&mut self, _: &ListType, v: FormatVersion) -> 
Result<FormatVersion> { Ok(v) }
       fn map(&mut self, _: &MapType, k: FormatVersion, v: FormatVersion) -> 
Result<FormatVersion> {
           Ok(k.max(v))
       }
       fn primitive(&mut self, p: &PrimitiveType) -> Result<FormatVersion> {
           Ok(match p {
               PrimitiveType::TimestampNs | PrimitiveType::TimestamptzNs => 
FormatVersion::V3,
               _ => FormatVersion::V1,
           })
       }
       fn variant(&mut self, _: &VariantType) -> Result<FormatVersion> { 
Ok(FormatVersion::V3) }
   }
   ```



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