jayzhan211 commented on code in PR #27701:
URL: https://github.com/apache/datafusion/pull/27701#discussion_r4725841979
##########
datafusion/common/src/nested_struct.rs:
##########
@@ -331,12 +331,13 @@ fn cast_list_column<O: arrow::array::OffsetSizeTrait>(
cast_options,
)?;
- let result = GenericListArray::<O>::new(
+ let result = GenericListArray::<O>::try_new(
Review Comment:
@Surajsuthar thanks for the fix! The change itself looks right, but nothing
tests it: with `try_new` reverted to `new`, all 670 `datafusion-common` lib
tests still pass. Could you add a regression test covering both `List` and
`LargeList`? This one panics on main and passes on this branch. It can go after
`test_cast_fixed_size_list_returns_error_for_non_nullable_child`:
```rs
#[test]
fn test_cast_list_struct_null_item_to_non_nullable_returns_error() {
let fields = Fields::from(vec![field("a", DataType::Int64)]);
let source_field = arc_field("item", Struct(fields.clone()));
let target_field = Arc::new(non_null_field("item",
Struct(fields.clone())));
// [{a: 1}, NULL]
let items: ArrayRef = Arc::new(StructArray::new(
fields,
vec![Arc::new(Int64Array::from(vec![1, 0])) as ArrayRef],
Some(NullBuffer::from(vec![true, false])),
));
let list: ArrayRef = Arc::new(ListArray::new(
Arc::clone(&source_field),
OffsetBuffer::from_lengths([2]),
Arc::clone(&items),
None,
));
let target_type = DataType::List(Arc::clone(&target_field));
let error = cast_column(&list, &target_type, &DEFAULT_CAST_OPTIONS)
.unwrap_err()
.to_string();
assert_contains!(error, "Non-nullable field of ListArray");
let large_list: ArrayRef = Arc::new(GenericListArray::<i64>::new(
source_field,
OffsetBuffer::from_lengths([2]),
items,
None,
));
let target_type = DataType::LargeList(target_field);
let error = cast_column(&large_list, &target_type, &DEFAULT_CAST_OPTIONS)
.unwrap_err()
.to_string();
assert_contains!(error, "Non-nullable field of LargeListArray");
}
```
--
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]