This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 0413c017e0 fix(arrow-cast): preserve length when casting zero-width
FixedSizeListArray (#11043)
0413c017e0 is described below
commit 0413c017e093b989e61692f277ae6ea78125d97c
Author: RIchard Baah <[email protected]>
AuthorDate: Tue Sep 15 01:03:49 2026 -0400
fix(arrow-cast): preserve length when casting zero-width FixedSizeListArray
(#11043)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- Closes None.
# Rationale for this change
`try_new` can't infer length when size == 0 (0 / 0 is ambiguous), so
route through `try_new_with_length` in that case.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
Branch on `size == 0 && nulls.is_none()` to pass length explicitly;
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
# Are these changes tested?
yes, added a regression test
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->
# Are there any user-facing changes?
no
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
---
arrow-cast/src/cast/mod.rs | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs
index 03abb14d27..c0e5327c1d 100644
--- a/arrow-cast/src/cast/mod.rs
+++ b/arrow-cast/src/cast/mod.rs
@@ -870,11 +870,14 @@ pub fn cast_with_options(
}
let array = array.as_fixed_size_list();
let values = cast_with_options(array.values(),
list_to.data_type(), cast_options)?;
- Ok(Arc::new(FixedSizeListArray::try_new(
+ let nulls = array.nulls().cloned();
+ let len = array.len();
+ Ok(Arc::new(FixedSizeListArray::try_new_with_length(
list_to.clone(),
*size_from,
values,
- array.nulls().cloned(),
+ nulls,
+ len,
)?))
}
(ListView(_), ListView(to)) => cast_list_view_values::<i32>(array, to,
cast_options),
@@ -9395,6 +9398,26 @@ mod tests {
assert_eq!(946684800000, c.value(5));
}
+ #[test]
+ fn test_cast_zero_width_fsl_to_fsl() {
+ // size=0 FSL with no nulls: length cannot be inferred from the child
buffer
+ // (0 bytes / 0 = ambiguous), so the cast must preserve it explicitly.
+ let field = Arc::new(Field::new_list_field(DataType::Int32, true));
+ let input = FixedSizeListArray::try_new_with_length(
+ field,
+ 0,
+ Arc::new(Int32Array::new_null(0)),
+ None,
+ 3,
+ )
+ .unwrap();
+ let to_type =
+
DataType::FixedSizeList(Arc::new(Field::new_list_field(DataType::Int64, true)),
0);
+ let result = cast(&(Arc::new(input) as ArrayRef), &to_type).unwrap();
+ assert_eq!(result.len(), 3);
+ assert_eq!(result.data_type(), &to_type);
+ }
+
#[test]
#[cfg_attr(miri, ignore)] // Unsupported inline assembly
fn test_can_cast_fsl_to_fsl() {