Repository navigation
fix(arrow-cast): preserve null rows when casting size-1 FixedSizeList - #12533
ApacheWang wants to merge 3 commits into
Conversation
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
|
|
||
| // Skip masked child values so a strict cast cannot fail on a null row. | ||
| let valid = BooleanArray::new(nulls.inner().clone(), None); | ||
| let values = filter(values.as_ref(), &valid)?; |
There was a problem hiding this comment.
we probably should gate this filter to only execute for strict casts
| .iter() | ||
| .map(|valid| if valid { valid_indices.next() } else { None }) | ||
| .collect(); | ||
| take(values.as_ref(), &indices, None) |
There was a problem hiding this comment.
i wonder if there is a better way to do this null masking; especially for the strict = false case, we could probably just operate directly on the null buffers. there is a caveat that some array types wont have a null buffer (run array & union array) so probably can keep this type of fallback for them
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
94d3c0f to
8a8d135
Compare
|
Good suggestions, thanks @Jefffrey! Updated in
|
Ap-95671
left a comment
There was a problem hiding this comment.
I reproduced a safe-cast regression at 8a8d135 and verified that the same case passes on 071e3a1. The inline comment describes the masked child case and a tested fallback. AI-assisted review with OpenAI Codex.
| return take(values.as_ref(), &indices, None); | ||
| } | ||
|
|
||
| let values = cast_with_options(values, to, cast_options)?; |
There was a problem hiding this comment.
A safe cast can return an error here before apply_null_mask runs. I tested a size-one FixedSizeList<Struct<number: Utf8 not null>> with child strings ["2", "invalid"] and parent validity [true, false]. Casting to Struct<number: Int32 not null> should return [{number: 2}, null], but 8a8d135 reports an unmasked null in number. The first PR revision passes the same test because it filters the null list row first. Could the direct path fall back to the existing filter/cast/take path on error? That variant passed the arrow-cast suite with the regression case.
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
|
Good catch, thanks for reproducing that case, @Ap-95671! Updated in
|
Which issue does this PR close?
Rationale for this change
Casting a size-1
FixedSizeListArrayto its child (or target) type viacast_single_element_fixed_size_list_to_valuescurrently delegates directly tocast_with_options(array.values(), to, cast_options)without consultingarray.nulls().As a result:
99becomesSome(99)instead ofNone).CastOptions { safe: false, .. }, invalid masked child values in null rows (such as"invalid"when casting toInt32) cause the cast to fail even though those rows are null.What changes are included in this PR?
cast_single_element_fixed_size_list_to_valuesinarrow-cast/src/cast/list.rsso that whenarray.nulls()has at least one null:array.values()to only valid parent rows before callingcast_with_options, preventing masked child values from failing strict casts.takeusing nullable indices derived fromarray.nulls(), preserving null rows while keeping the zero-copy fast path whennull_count() == 0.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_nullsinarrow-cast/tests/cast/list.rs, covering:FixedSizeList<Utf8, 1>cast toInt32under bothsafe: trueandsafe: falsewith masked numeric and invalid child values alongside inner nulls.FixedSizeList<Int32, 1>unwrap toInt32with masked values under null rows.FixedSizeList<Int32, 1>cast toInt32.FixedSizeList<Struct, 1>with a non-nullable struct child field under a null list row.Dictionarytarget type (safe: false).Are there any significant user-facing changes?
No (bug fix only; null rows in size-1
FixedSizeListcasts 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-casttest suite,rustfmt, andclippylocally.