liamzwbao commented on code in PR #9338:
URL: https://github.com/apache/arrow-rs/pull/9338#discussion_r2761791785
##########
arrow-string/src/regexp.rs:
##########
@@ -180,7 +180,6 @@ pub fn regexp_is_match_scalar<'a, S>(
where
&'a S: StringArrayType<'a>,
{
- let null_bit_buffer = array.nulls().map(|x| x.inner().sliced());
Review Comment:
We don't have `.sliced()` unfortunately, but we could rebuild the
`NullBuffer`
##########
arrow-string/src/substring.rs:
##########
@@ -360,24 +345,29 @@ fn fixed_size_binary_substring(
})
.for_each(|(start, end)|
new_values.extend_from_slice(&data[start..end]));
- let array_data = unsafe {
- ArrayData::new_unchecked(
- DataType::FixedSizeBinary(new_len),
- num_of_elements,
- None,
- array.nulls().map(|b| b.inner().sliced()),
- 0,
- vec![new_values.into()],
- vec![],
- )
+ let nulls = if new_len == 0 {
+ // FixedSizeBinaryArray::new takes length from the values buffer,
except when size == 0.
+ // In that case it uses the null buffer length, so preserve the
original length here.
+ // Example: ["", "", ""] -> substring(..., 1, Some(2)) should keep
len=3;
+ // otherwise it collapses to an empty array (len=0).
+ array
+ .nulls()
+ .cloned()
+ .or_else(|| Some(NullBuffer::new_valid(num_of_elements)))
Review Comment:
That's mainly because `FixedSizeBinaryArray::new` treats `size == 0`
specially: if both `values` and `nulls` are `None`, it infers `len = 0`.
https://github.com/apache/arrow-rs/blob/7291147175a11a4748d9ea5a06ea42807bf36e3c/arrow-array/src/array/fixed_size_binary_array.rs#L97-L105
In `substring::tests::without_nulls_fixed_size_binary`, some cases produce
size‑0 substrings, and without this change the result collapses to an empty
array and fail the tests. Providing a `nulls` buffer here simply preserves the
expected length to produce correct results (e.g., `["", "", ""]`).
--
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]