Skip to content

Split oversized record batches when streaming writes #4499

Backlog

Description

@Fokko

Follow up to #3447.

Since #3447, tbl.append() and tbl.overwrite() accept any Arrow PyCapsule stream, such as a Polars DataFrame, and stream it into unpartitioned tables through bin_pack_record_batches. That function never splits a batch, and a Polars DataFrame built in one go exports a single chunk, so the whole frame ends up in one data file regardless of write.target-file-size-bytes. Converting with pa.table(df) first goes through bin_pack_arrow_table, which does split by rows.

With 500k rows and write.target-file-size-bytes=1048576 on an unpartitioned table:

tbl.append(pa.table(polars_df))  # 18 data files
tbl.append(polars_df)            # 1 data file

The same applies to any pa.RecordBatchReader that yields large batches.

Proposal: in bin_pack_record_batches, slice an incoming batch that would push the buffer past the target size (RecordBatch.slice is zero copy), so streamed input honors the target file size the same way pa.Table input does. Once that's in, the "A streamed batch is never split" note in mkdocs/docs/api.md can be dropped.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions