BatchCoalescer: add a target batch size in bytes

Aperta
#12,508 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@ranflarion ci sta già lavorando.

Dal 29/11/2026.

  • #12509 di @ranflarion — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
data

Direzione di ricerca

Find BatchCoalescer and its primitive and view builders in the Rust source; read how batches are sized, finished, and allocated, then trace the existing biggest_coalesce_batch_size bypass. Implement the optional byte target using the stated per-batch average row size and right-sized output buffers. Done means byte-targeted batches split as described, including oversized batches and single rows, while behavior without a target remains unchanged; add or run the relevant tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is your feature request related to a problem or challenge?

BatchCoalescer completes an output batch at target_batch_size rows and has no notion of bytes. With wide rows that makes very large batches: 8,192 rows of 10,000 Float64 columns are 655 MB, and 8,192 rows that each hold a 100 KB list are about 800 MB. Operators downstream then have to buffer, sort or spill such a batch whole. DataFusion's sort reserves roughly twice a batch's size before buffering it, so one of these batches fails a memory-limited query that has plenty of room for the same rows in smaller batches.

A caller cannot fix this from outside. Lowering target_batch_size penalizes narrow rows, and the row width is not known before the data arrives and can change during a stream. Calling finish_buffered_batch early does cut a batch, but the primitive and view builders reserve target_batch_size values for every output batch and hand that capacity to the array, so a batch cut at 100 rows still holds buffers allocated for 8,192.

Describe the solution you'd like

An optional byte target next to the row target:

let coalescer = BatchCoalescer::new(schema, 8192)
    .with_target_batch_bytes(Some(32 * 1024 * 1024));

With a target, an output batch is also completed once the rows buffered for it reach that many bytes. Each row counts as an equal share of the batch it arrived in (ArrayData::get_slice_memory_size divided by the row count), which costs one pass over the columns per pushed batch and nothing per row. A batch larger than the target is split instead of taking the biggest_coalesce_batch_size bypass, a single row larger than the target is a batch of its own, and each output batch's buffers are allocated for the rows it is expected to hold. Without a target nothing changes.

Describe alternatives you've considered
  • A wrapper around BatchCoalescer that measures input batches and calls finish_buffered_batch. It cannot avoid the full-size allocation described above, and it cannot split a filtered push without materializing it first.
  • Exact per-row sizes instead of the batch average. That is precise for rows of uneven size, but needs a pass over the offsets of every variable-width column, nested ones included. The average keeps the cost per batch and can be refined later.
  • A re-chunking operator in the query engine (apache/datafusion#23390 proposed one for data sources). It bounds what one operator emits, but every operator that coalesces after it builds large batches again.
Additional context

DataFusion's filter, hash join, sort-merge join and nested loop join build their output through BatchCoalescer, so a target here gives each of them a byte bound with one builder call.

Willingness to contribute

I plan to contribute to this feature independently

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-rs

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.