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


##########
crates/iceberg/src/spec/schema/mod.rs:
##########
@@ -421,6 +425,67 @@ impl Schema {
     pub fn field_id_to_fields(&self) -> &HashMap<i32, NestedFieldRef> {
         &self.id_to_field
     }
+
+    /// Returns the minimum [`FormatVersion`] required to represent all types 
in this schema.
+    ///
+    /// Defaults to `FormatVersion::V1` if all types are universally supported.
+    pub fn min_format_version(&self) -> FormatVersion {
+        self.as_struct()
+            .fields()
+            .iter()
+            .map(|f| f.field_type.min_format_version())
+            .max()
+            .unwrap_or(FormatVersion::V1)
+    }
+
+    /// Check that all types in this schema are supported by the given format 
version.
+    ///
+    /// Mirrors Java's `Schema.checkCompatibility()`; returns an error listing 
every
+    /// incompatible field. Two checks per field:
+    ///
+    /// - **Type**: `TimestampNs` / `TimestamptzNs` / `Variant` require v3+.
+    /// - **Initial default**: a non-null `initial_default` requires
+    ///   [`MIN_FORMAT_VERSION_DEFAULT_VALUES`] — it backfills pre-existing 
rows,
+    ///   which older readers can't honor. `write_default` only affects newly
+    ///   written rows (physically materialized, read the same at any 
version), so
+    ///   it is not checked.
+    pub fn check_format_compatibility(&self, format_version: FormatVersion) -> 
Result<()> {
+        let mut problems: Vec<String> = Vec::new();
+
+        for field in self.id_to_field.values() {
+            let name = self
+                .name_by_field_id(field.id)
+                .unwrap_or(field.name.as_str());
+
+            let min_version = field.field_type.min_format_version();

Review Comment:
   Switched to Java's shape: a shallow `leaf_min_format_version(&Type)` (a 
match, like Java's `MIN_FORMAT_VERSIONS` TypeID lookup) applied per field over 
the flattened id_to_field (like `lazyIdToField()`) — no recursion. This also 
fixed a real bug the recursion caused: it blamed the container for a nested v3 
type.
   
   We have a test for it now.



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