c-thiel commented on code in PR #2188:
URL: https://github.com/apache/iceberg-rust/pull/2188#discussion_r3357485228
##########
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<()> {
Review Comment:
Addressed together with the visitor discussion above —
https://github.com/apache/iceberg-rust/pull/2188#discussion_r3348251286
--
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]