odysa commented on code in PR #7896: URL: https://github.com/apache/arrow-rs/pull/7896#discussion_r2200735666
########## parquet-variant/src/builder.rs: ########## @@ -2171,4 +2171,116 @@ mod tests { let variant = Variant::try_new_with_metadata(metadata, &value).unwrap(); assert_eq!(variant, Variant::Int8(2)); } + + fn test_variant_object_with_count(count: i32, expected_field_id_size_minus_one: u8) { + let mut builder = VariantBuilder::new(); + let mut obj = builder.new_object(); + + for val in 0..count { + let key = format!("id_{}", val); + obj.insert(&key, val); + } + + obj.finish().unwrap(); + let (metadata, value) = builder.finish(); + let variant = Variant::try_new(&metadata, &value).unwrap(); + + if let Variant::Object(obj) = variant { + assert_eq!(obj.len(), count as usize); + assert_eq!(obj.get(&format!("id_{}", 0)).unwrap(), Variant::Int32(0)); + assert_eq!( + obj.get(&format!("id_{}", count - 1)).unwrap(), + Variant::Int32(count - 1) + ); + + let header_byte = first_byte_from_slice(&value).unwrap(); + let value_header = header_byte >> 2; + let field_id_size_minus_one = (value_header >> 2) & 0x03; + assert_eq!( + field_id_size_minus_one, expected_field_id_size_minus_one, + "Expected {}-byte field IDs", + expected_field_id_size_minus_one + ); + } else { + panic!("Expected object variant"); + } + } + + #[test] + fn test_variant_object_257_elements() { + test_variant_object_with_count(2_i32.pow(8) + 1, 1); // 2^8 + 1, expected 2-byte field IDs + } + + #[test] + fn test_variant_object_65537_elements() { + test_variant_object_with_count(2_i32.pow(16) + 1, 2); // 2^16 + 1, expected 3-byte field IDs + } + + #[test] + #[ignore] Review Comment: Inserting 2²⁴ fields took 66 seconds on my laptop. I've marked it as ignored for now while I explore a faster approach. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org