This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-3635-b058267a71a067f2782ff710ab03c4c250c51959 in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
commit ac3bae41ffb56b8652a23fee9b41d532dd5f250b Author: Burak <[email protected]> AuthorDate: Wed Nov 25 23:47:42 2026 +0000 fix(spec): read the manifest schema id from the schema when schema-id is missing (#3635) * fix(spec): read the manifest schema id from the schema when schema-id is missing * test: build one v2 header in the manifest metadata tests --------- Co-authored-by: Burak Ozakinci <[email protected]> --- crates/iceberg/src/spec/manifest/metadata.rs | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/iceberg/src/spec/manifest/metadata.rs b/crates/iceberg/src/spec/manifest/metadata.rs index b06122215..0b25c35d5 100644 --- a/crates/iceberg/src/spec/manifest/metadata.rs +++ b/crates/iceberg/src/spec/manifest/metadata.rs @@ -59,7 +59,7 @@ impl ManifestMetadata { }) }) .transpose()? - .unwrap_or(0); + .unwrap_or(schema.schema_id()); let partition_spec = { let fields = { let bs = meta.get("partition-spec").ok_or_else(|| { @@ -132,3 +132,36 @@ impl ManifestMetadata { &self.content } } + +#[cfg(test)] +mod tests { + use super::*; + + fn metadata_without_schema_id() -> HashMap<String, Vec<u8>> { + HashMap::from([ + ( + "schema".to_string(), + br#"{"type":"struct","schema-id":3,"fields":[]}"#.to_vec(), + ), + ("partition-spec".to_string(), b"[]".to_vec()), + ("partition-spec-id".to_string(), b"0".to_vec()), + ("format-version".to_string(), b"2".to_vec()), + ("content".to_string(), b"data".to_vec()), + ]) + } + + #[test] + fn test_parse_takes_schema_id_from_schema_when_key_is_missing() { + let metadata = ManifestMetadata::parse(&metadata_without_schema_id()).unwrap(); + + assert_eq!(metadata.schema_id(), 3); + } + + #[test] + fn test_parse_prefers_schema_id_key_over_schema() { + let mut meta = metadata_without_schema_id(); + meta.insert("schema-id".to_string(), b"5".to_vec()); + + assert_eq!(ManifestMetadata::parse(&meta).unwrap().schema_id(), 5); + } +}
