Skip to content

fix(arrow-select): compact nested view buffers in BatchCoalescer (#12530) - #12531

Open
Mola-maker wants to merge 2 commits into
apache:mainfrom
Mola-maker:fix/12530-batch-coalescer-nested-view-compact
Open

Mola-maker wants to merge 2 commits into
apache:mainfrom
Mola-maker:fix/12530-batch-coalescer-nested-view-compact

Conversation

@Mola-maker

@Mola-maker Mola-maker commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

BatchCoalescer compacted top-level view columns after a sparse take. Nested views in List, Struct, Map, and FixedSizeList kept the whole source buffers.

What changes are included in this PR?

  • BatchCoalescer::finish_buffered_batch now walks finished columns and compacts nested view arrays whose buffers hold more than twice the bytes their values use.
  • Containers are rebuilt only when a child actually changes.

Are these changes tested?

Yes. Two new tests cover the sparse take from the issue for Utf8View and BinaryView in List, Struct, FixedSizeList, Map, and a List of Struct.
verification

Are there any significant user-facing changes?

No.

AI usage disclosure

Harness: Muse
Model: Muse Spark
Effort: default
Role: Muse drafted the investigation, fix, and tests under my direction; I reviewed the diff and ran the tests.

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

@Ap-95671 Ap-95671 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified the inline-only sparse selection on this revision. The targeted test reproduced 90,000 bytes retained. After a local adjustment to the zero-usage guard, all 75 coalescing tests passed, including the added case.

AI-assisted review with OpenAI Codex, submitted on behalf of Ap-95671.

) -> Option<GenericByteViewArray<T>> {
let used = array.total_buffer_bytes_used();
if used == 0 {
return None;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One edge case to consider: a sparse take can retain only inline values, so used is zero while the nested child still owns its original backing buffers. Reusing the sparse-take test setup with 100 selected inline rows and 900 unselected 100-byte values, List<Utf8View> kept 90,000 backing bytes while top-level Utf8View kept zero. Letting zero reach the existing capacity check dropped the buffers in the reproduction. gc() has a fast path that reuses the inline views, so it does not copy the string payload. An early data_buffers().is_empty() check would keep buffer-free arrays cheap. Could the sparse-take test cover this case too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 41e7180. The zero-usage guard is gone. An inline-only selection now reaches the capacity check and drops its backing buffers. Buffer-free arrays still skip the check through data_buffers().is_empty(). The sparse-take test now covers the inline-only case.

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.

BatchCoalescer retains oversized data buffers for nested view arrays

2 participants