This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch 59_maintenance
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/59_maintenance by this push:
new 4dcf789b44 [59_maintenance] fix(arrow-cast): avoid panicking during
failed List -> ListView cast (#11445)
4dcf789b44 is described below
commit 4dcf789b44db38a271f05fa63c22f081b14ede82
Author: Jeffrey Vo <[email protected]>
AuthorDate: Fri Oct 9 03:23:28 2026 +0900
[59_maintenance] fix(arrow-cast): avoid panicking during failed List ->
ListView cast (#11445)
- Backport https://github.com/apache/arrow-rs/pull/11355
- For inclusion in https://github.com/apache/arrow-rs/issues/11352
Cherry-pick of
https://github.com/apache/arrow-rs/commit/6d44c7c5ec45eb54ba2517179bcda5f786aceb85
Co-authored-by: Neil Conway <[email protected]>
---
arrow-cast/src/cast/list.rs | 4 ++--
arrow-cast/src/cast/mod.rs | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/arrow-cast/src/cast/list.rs b/arrow-cast/src/cast/list.rs
index fc07768a73..d9763e799e 100644
--- a/arrow-cast/src/cast/list.rs
+++ b/arrow-cast/src/cast/list.rs
@@ -487,12 +487,12 @@ pub(crate) fn cast_list_to_list_view<I: OffsetSizeTrait,
O: OffsetSizeTrait>(
sizes.push(O::usize_as(size));
}
let values = cast_with_options(&values, to_field.data_type(),
cast_options)?;
- let array = GenericListViewArray::<O>::new(
+ let array = GenericListViewArray::<O>::try_new(
to_field.clone(),
view_offsets.into(),
sizes.into(),
values,
nulls,
- );
+ )?;
Ok(Arc::new(array))
}
diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs
index 20a3068e95..e65867aaf4 100644
--- a/arrow-cast/src/cast/mod.rs
+++ b/arrow-cast/src/cast/mod.rs
@@ -13647,6 +13647,28 @@ mod tests {
assert_eq!(got_list_view, &expected_list_view);
}
+ #[test]
+ fn test_cast_list_to_list_view_null_in_non_nullable_field() {
+ // i32::MAX does not fit in Int16, so a safe cast turns it into a null
+ let list = ListArray::from_iter_primitive::<Int32Type, _,
_>([Some(vec![
+ Some(1),
+ Some(i32::MAX),
+ ])]);
+ let field = Arc::new(Field::new_list_field(DataType::Int16, false));
+ for (target_type, array_name) in [
+ (DataType::ListView(field.clone()), "ListViewArray"),
+ (DataType::LargeListView(field), "LargeListViewArray"),
+ ] {
+ let err = cast(&list, &target_type).unwrap_err();
+ assert_eq!(
+ err.to_string(),
+ format!(
+ "Invalid argument error: Non-nullable field of
{array_name} \"item\" cannot contain nulls"
+ )
+ );
+ }
+ }
+
#[test]
fn test_cast_large_list_view_to_large_list() {
let list_view =