EmilyMatt commented on code in PR #18745:
URL: https://github.com/apache/datafusion/pull/18745#discussion_r2532043718
##########
datafusion/datasource-avro/src/avro_to_arrow/arrow_array_reader.rs:
##########
@@ -1720,4 +1716,91 @@ mod test {
assert_eq!(2, num_batches);
assert_eq!(28, sum_id);
}
+
+ #[test]
+ fn test_list_of_structs_with_custom_field_name() {
+ let schema = apache_avro::Schema::parse_str(
+ r#"
+ {
+ "type": "record",
+ "name": "root",
+ "fields": [
+ {
+ "name": "items",
+ "type": {
+ "type": "array",
+ "items": {
+ "type": "record",
+ "name": "item_record",
+ "fields": [
+ {
+ "name": "id",
+ "type": "long"
+ },
+ {
+ "name": "name",
+ "type": "string"
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }"#,
+ )
+ .unwrap();
+
+ let r1 = apache_avro::to_value(serde_json::json!({
+ "items": [
+ {
+ "id": 1,
+ "name": "first"
+ },
+ {
+ "id": 2,
+ "name": "second"
+ }
+ ]
+ }))
+ .unwrap()
+ .resolve(&schema)
+ .unwrap();
+
+ let mut w = apache_avro::Writer::new(&schema, vec![]);
+ w.append(r1).unwrap();
+ let bytes = w.into_inner().unwrap();
+
+ // Create an Arrow schema where the list field is NOT named "element"
+ let arrow_schema =
Arc::new(arrow::datatypes::Schema::new(vec![Field::new(
+ "items",
+ DataType::List(Arc::new(Field::new(
+ "item", // This is NOT "element"
+ DataType::Struct(Fields::from(vec![
+ Field::new("id", DataType::Int64, false),
+ Field::new("name", DataType::Utf8, false),
+ ])),
+ false,
+ ))),
+ false,
+ )]));
+
+ let mut reader = ReaderBuilder::new()
+ .with_schema(arrow_schema)
+ .with_batch_size(10)
+ .build(std::io::Cursor::new(bytes))
+ .unwrap();
+
+ // This should fail because schema_lookup will have "items.element.id"
and "items.element.name"
Review Comment:
You're right, thank you^
--
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]