BatchCoalescer: add a target batch size in bytes

オープン
#12,508 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@ranflarion がすでに取り組んでいます。

2026年11月29日 から。

  • #12509 @ranflarion による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
3.7k
フォーク
1.5k
平均マージ
2日 16時間
マージ済み PR(30日)
183

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/arrow-rs のほかの issue

apache/arrow-rs の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。