This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-11625-88b5c5a3952bc715fa8d13d76e45c407717b12b6 in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
commit f0e855f02ffe3c09ebe051558c21a5b52f7648e6 Author: Michael Kleen <[email protected]> AuthorDate: Sun Oct 18 09:33:29 2026 +0000 fix: Fix zip with a short falsy scalar that still has buffers (#11625) # Which issue does this PR close? - Closes #11593 # Rationale for this change A short falsy value is stored inline in its view, but a scalar sliced from a larger array can keep that array's buffers. Checking for buffers then wrongly rewrote the view. Check the value's length instead. # What changes are included in this PR? See above. # Are these changes tested? Yes. # Are there any significant user-facing changes? No. --- arrow-select/src/zip.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/arrow-select/src/zip.rs b/arrow-select/src/zip.rs index 1abde41d16..a0381eff1c 100644 --- a/arrow-select/src/zip.rs +++ b/arrow-select/src/zip.rs @@ -29,7 +29,7 @@ use arrow_buffer::{ ToByteSlice, }; use arrow_data::transform::MutableArrayData; -use arrow_data::{ArrayData, ByteView}; +use arrow_data::{ArrayData, ByteView, MAX_INLINE_VIEW_LEN}; use arrow_schema::{ArrowError, DataType}; use std::fmt::{Debug, Formatter}; use std::hash::Hash; @@ -814,10 +814,8 @@ impl<T: ByteViewType> ByteViewScalarImpl<T> { let true_count = predicate.count_set_bits(); let mut buffers: Vec<Buffer> = truthy_buffers.to_vec(); - // If the falsy buffers are empty, we can use the falsy view as it is, because the value - // is completely inlined. Otherwise, we have non-inlined values in the buffer, and we need - // to recalculate the falsy view - let view_falsy = if falsy_buffers.is_empty() { + // Check if we need to keep falsy buffer in case view isn't inline + let view_falsy = if (falsy_view as u32) <= MAX_INLINE_VIEW_LEN { falsy_view } else { let byte_view_falsy = ByteView::from(falsy_view); @@ -1748,4 +1746,58 @@ mod test { ]); assert_eq!(actual, &expected); } + + #[test] + fn test_zip_kernel_scalar_strings_array_view_sliced_inline() { + // Both scalars are inlined, but each slice keeps its array's data buffer + let truthy = + StringViewArray::from(vec!["x", "a string longer than twelve bytes"]).slice(0, 1); + let falsy = + StringViewArray::from(vec!["hello", "another string longer than twelve"]).slice(0, 1); + + let mask = BooleanArray::from(vec![true, false, true, false]); + let out = zip(&mask, &Scalar::new(&truthy), &Scalar::new(&falsy)).unwrap(); + out.to_data().validate_full().unwrap(); + let actual = out.as_string_view(); + let expected = StringViewArray::from(vec!["x", "hello", "x", "hello"]); + assert_eq!(actual, &expected); + } + + #[test] + fn test_zip_kernel_scalar_strings_array_view_sliced_long_falsy() { + // A 13 byte falsy value is not inlined, so it must be remapped after the truthy buffers + let truthy = + StringViewArray::from(vec!["a string longer than twelve bytes", "x"]).slice(0, 1); + let falsy = StringViewArray::from(vec!["y", "thirteen byte"]).slice(1, 1); + + let mask = BooleanArray::from(vec![true, false]); + let out = zip(&mask, &Scalar::new(&truthy), &Scalar::new(&falsy)).unwrap(); + out.to_data().validate_full().unwrap(); + let actual = out.as_string_view(); + let expected = + StringViewArray::from(vec!["a string longer than twelve bytes", "thirteen byte"]); + assert_eq!(actual, &expected); + } + + #[test] + fn test_zip_kernel_scalar_binary_array_view_sliced_inline_max_len() { + // A 12 byte inlined value whose bytes 8 to 11 are 0xFF must not be read as a buffer index + let truthy = BinaryViewArray::from_iter_values([ + b"x".as_slice(), + b"another value longer than twelve", + ]) + .slice(0, 1); + let falsy = BinaryViewArray::from_iter_values([ + [0xFFu8; 12].as_slice(), + b"a value longer than twelve bytes", + ]) + .slice(0, 1); + + let mask = BooleanArray::from(vec![true, false]); + let out = zip(&mask, &Scalar::new(&truthy), &Scalar::new(&falsy)).unwrap(); + out.to_data().validate_full().unwrap(); + let actual = out.as_binary_view(); + let expected = BinaryViewArray::from_iter_values([b"x".as_slice(), &[0xFFu8; 12]]); + assert_eq!(actual, &expected); + } }
