tustvold opened a new issue, #3904:
URL: https://github.com/apache/arrow-rs/issues/3904
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
StructArrayDecoder currently is not correctly enforcing that children are
only permitted nulls in positions masked by their parents
**To Reproduce**
<!--
Steps to reproduce the behavior:
-->
```
#[test]
fn struct_nullability() {
let do_test = |child: DataType| {
// Test correctly enforced nullability
let non_null = r#"{"foo": {}}"#;
let schema = Arc::new(Schema::new(vec![Field::new(
"foo",
DataType::Struct(vec![Field::new("bar", child, false)]),
true,
)]));
let mut reader = RawReaderBuilder::new(schema.clone())
.build(Cursor::new(non_null.as_bytes()))
.unwrap();
assert!(reader.next().unwrap().is_err()); // Should error as not
nullable
// Test nulls in nullable parent can mask nulls in non-nullable child
let null = r#"{"foo": null}"#;
let mut reader = RawReaderBuilder::new(schema)
.build(Cursor::new(null.as_bytes()))
.unwrap();
let batch = reader.next().unwrap().unwrap();
assert_eq!(batch.num_columns(), 1);
let foo = as_struct_array(batch.column(0).as_ref());
assert_eq!(foo.len(), 1);
assert!(foo.is_null(1));
assert_eq!(foo.num_columns(), 1);
let bar = foo.column(0);
assert_eq!(bar.len(), 1);
// Non-nullable child can still contain null as masked by parent
assert!(bar.is_null(0));
};
do_test(DataType::Boolean);
do_test(DataType::Int32);
do_test(DataType::Utf8);
do_test(DataType::Decimal128(1, 2));
do_test(DataType::Timestamp(
TimeUnit::Microsecond,
Some("UTC".to_string()),
));
}
```
**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
**Additional context**
<!--
Add any other context about the problem here.
-->
This is the flip side of https://github.com/apache/arrow-rs/issues/3900
--
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]