ApacheWang opened a new pull request, #12533:
URL: https://github.com/apache/arrow-rs/pull/12533

   # Which issue does this PR close?
   
   - None (discovered directly during code review; no existing open issue).
   
   # Rationale for this change
   
   Casting a size-1 `FixedSizeListArray` to its child (or target) type via 
`cast_single_element_fixed_size_list_to_values` currently delegates directly to 
`cast_with_options(array.values(), to, cast_options)` without consulting 
`array.nulls()`.
   
   As a result:
   - Null list rows silently expose their masked underlying child values as 
non-null entries in the output array (e.g. a null row whose underlying child 
holds `99` becomes `Some(99)` instead of `None`).
   - Under `CastOptions { safe: false, .. }`, invalid masked child values in 
null rows (such as `"invalid"` when casting to `Int32`) cause the cast to fail 
even though those rows are null.
   
   # What changes are included in this PR?
   
   - Update `cast_single_element_fixed_size_list_to_values` in 
`arrow-cast/src/cast/list.rs` so that when `array.nulls()` has at least one 
null:
     1. Filter `array.values()` to only valid parent rows before calling 
`cast_with_options`, preventing masked child values from failing strict casts.
     2. Scatter the cast values back to the original length with `take` using 
nullable indices derived from `array.nulls()`, preserving null rows while 
keeping the zero-copy fast path when `null_count() == 0`.
   - Add regression tests in `arrow-cast/tests/cast/list.rs` 
(`test_cast_single_element_fixed_size_list_preserves_nulls`).
   
   # Are these changes tested?
   
   Yes. Added `test_cast_single_element_fixed_size_list_preserves_nulls` in 
`arrow-cast/tests/cast/list.rs`, covering:
   - Sliced `FixedSizeList<Utf8, 1>` cast to `Int32` under both `safe: true` 
and `safe: false` with masked numeric and invalid child values alongside inner 
nulls.
   - Same-type `FixedSizeList<Int32, 1>` unwrap to `Int32` with masked values 
under null rows.
   - All-null `FixedSizeList<Int32, 1>` cast to `Int32`.
   - `FixedSizeList<Struct, 1>` with a non-nullable struct child field under a 
null list row.
   - Casting through a `Dictionary` target type (`safe: false`).
   
   # Are there any significant user-facing changes?
   
   No (bug fix only; null rows in size-1 `FixedSizeList` casts now remain null 
instead of exposing masked child data).
   
   # AI usage disclosure
   
   AI assistance (Codex) helped identify the bug and draft the initial fix and 
test; I reviewed the edge cases (sliced buffers, all-null inputs, non-nullable 
struct children, dictionary targets), refined the tests, and verified the full 
`arrow-cast` test suite, `rustfmt`, and `clippy` locally.
   


-- 
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]

Reply via email to