Skip to content

fix(arrow-select): only retain referenced buffers when zipping scalar byte views - #12551

Open
ryanvickr wants to merge 1 commit into
apache:mainfrom
ryanvickr:fix/zip-scalar-byte-view-buffers
Open

ryanvickr wants to merge 1 commit into
apache:mainfrom
ryanvickr:fix/zip-scalar-byte-view-buffers

Conversation

@ryanvickr

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

When zipping two scalar StringView or BinaryView values (directly with zip or via ScalarZipper), each scalar represents a single value, so it can reference at most one buffer (zero buffers if inlined, or one buffer if out-of-line).

Previously, zipping cloned and retained the entire data_buffers() slice from each scalar array. When scalars were sliced from larger multi-buffer arrays, unreferenced buffers stayed alive in both ScalarZipper and every output array it produced.

What changes are included in this PR?

In arrow-select/src/zip.rs:

  • Normalize each non-null scalar in ByteViewScalarImpl to hold only the single Buffer it references (none for inline or null scalars; one buffer with buffer_index rewritten to 0 for out-of-line scalars).
  • Emit 0 buffers for empty (len == 0) or all-inline outputs, 1 buffer when both out-of-line scalars reference the same buffer (Buffer::ptr_eq), and 2 buffers when they reference distinct buffers.
  • Assert empty data_buffers() in existing sliced-inline tests and add unit tests covering multi-buffer StringViewArray and BinaryViewArray slices, shared buffers, single non-null scalars with null masks, empty masks, and ScalarZipper reuse.

Are these changes tested?

Yes. Existing and new unit tests are included in arrow_select::zip::test:

  • test_zip_kernel_scalar_strings_array_view_sliced_inline (now asserts data_buffers().is_empty())
  • test_zip_kernel_scalar_binary_array_view_sliced_inline_max_len (now asserts data_buffers().is_empty())
  • test_zip_scalar_byte_view_only_retains_referenced_buffers
  • test_zip_scalar_byte_view_single_non_null_buffer_retention
  • test_scalar_zipper_byte_view_reuse_minimal_buffers

Are there any significant user-facing changes?

No breaking API changes. Output arrays from zip and ScalarZipper on StringView and BinaryView scalars now retain only the buffers actually referenced by the output views (0, 1, or 2 buffers).

AI usage disclosure

AI coding assistance was used to draft the implementation, unit tests, and PR description; all code changes and test results were reviewed by the author.

@boring-cyborg boring-cyborg Bot added the arrow-kernels Crates that transform arrow data (e.g. compute, cast) label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-kernels Crates that transform arrow data (e.g. compute, cast)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zip with scalar byte view types retain all buffers

1 participant