jecsand838 commented on code in PR #8254: URL: https://github.com/apache/arrow-rs/pull/8254#discussion_r2312095645
########## arrow-avro/src/reader/record.rs: ########## @@ -1471,4 +1485,111 @@ mod tests { assert!(int_array.is_null(0)); // row1 is null assert_eq!(int_array.value(1), 42); // row3 value is 42 } + + #[test] + fn test_map_with_non_nullable_value_type() { + let schema_json = r#"{ + "type": "record", + "name": "MapRecord", + "fields": [ + {"name": "map_field", "type": { "type": "map", "values": "string" }} + ] + }"#; + + let schema: AvroSchema = serde_json::from_str(schema_json).unwrap(); + let field = AvroField::try_from(&schema).unwrap(); + let mut decoder = RecordDecoder::try_new_with_options(field.data_type(), true).unwrap(); + + let mut data = Vec::new(); + data.extend_from_slice(&encode_avro_long(1)); // 1 entry in map + data.extend_from_slice(&encode_avro_bytes(b"key")); // key + data.extend_from_slice(&encode_avro_bytes(b"value")); // value + data.extend_from_slice(&encode_avro_long(0)); // end map + + decoder.decode(&data, 1).unwrap(); + + let batch = decoder.flush().unwrap(); + assert_eq!(batch.num_columns(), 1); + assert_eq!(batch.num_rows(), 1); + + let map_arr = batch.column(0).as_any().downcast_ref::<MapArray>().unwrap(); + assert_eq!(map_arr.len(), 1); + assert_eq!(map_arr.value_length(0), 1); + + let entries = map_arr.value(0); + let key_arr = entries.column(0).as_string::<i32>(); + let val_arr = entries.column(1).as_string::<i32>(); + assert_eq!(key_arr.value(0), "key"); + assert_eq!(val_arr.value(0), "value"); + } + + #[test] + fn test_map_with_nullable_value_type() { + let schema_json = r#"{ + "type": "record", + "name": "MapRecord", + "fields": [ + {"name": "map_field1", "type": { "type": "map", "values": ["null", "string"] }}, + {"name": "map_field2", "type": { "type": "map", "values": ["string", "null"] }} + ] + }"#; + + let schema: AvroSchema = serde_json::from_str(schema_json).unwrap(); Review Comment: Not trying to be too nitty with this, there's just a separate struct named `AvroSchema` defined in `arrow-avro/src/schema.rs` ```suggestion let schema: Schema = serde_json::from_str(schema_json).unwrap(); ``` -- 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