gengliangwang opened a new issue, #3837:
URL: https://github.com/apache/iceberg-rust/issues/3837

   ### Apache Iceberg Rust version
   
   main (`ea17ba2`)
   
   ### Describe the bug
   
   `TableMetadata` keeps its schemas, partition specs, sort orders, snapshots, 
statistics, partition statistics and encryption keys in `HashMap`s, and a 
`Schema` keeps its identifier field ids in a `HashSet`. Serialization writes 
them with `into_values().collect()` / `into_iter().collect()` 
(`crates/iceberg/src/spec/table_metadata.rs`, `_serde`; 
`crates/iceberg/src/spec/schema/_serde.rs`), so the lists in the metadata file 
come out in the maps' iteration order:
   
   - `schemas`, `partition-specs`, `sort-orders`, `snapshots`, `statistics`, 
`partition-statistics` and `encryption-keys` are in a random order that changes 
from one write to the next, and from one process to the next;
   - `identifier-field-ids` of a schema likewise.
   
   The same table metadata therefore produces a different file each time it is 
written. Two consecutive metadata files of a table differ in the order of every 
list, not only in what the commit changed, and the snapshots are not in the 
order in which they were committed.
   
   Iceberg's Java library keeps these as lists and writes them in the order in 
which they were added: schemas, specs and sort orders by increasing id, and 
snapshots in commit order.
   
   ### To Reproduce
   
   Read a metadata file with several schemas (or snapshots) and write it back:
   
   ```rust
   let metadata: TableMetadata = serde_json::from_str(&json).unwrap(); // ten 
schemas, ids 0..=9
   let written = serde_json::to_value(&metadata).unwrap();
   let ids: Vec<i64> = written["schemas"]
       .as_array()
       .unwrap()
       .iter()
       .map(|schema| schema["schema-id"].as_i64().unwrap())
       .collect();
   assert_eq!(ids, (0..=9).collect::<Vec<_>>()); // fails: the order is 
arbitrary
   ```
   
   ### Expected behavior
   
   The lists are written in a stable order: schemas, partition specs, sort 
orders, statistics and encryption keys by their ids, snapshots in the order in 
which they were committed, and identifier field ids in ascending order.
   
   ### Willingness to contribute
   
   I can contribute a fix for this bug independently
   


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