Repository navigation
Conversation
bin_pack_record_batches never split an incoming batch, so a streamed input that exports a single large batch (for example a Polars DataFrame through the PyCapsule interface) was written as one data file regardless of write.target-file-size-bytes. Slice a batch that would push the buffer past the target size so streamed writes honor the target file size like Table input does.
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Since #3447,
tbl.append()andtbl.overwrite()accept any Arrow PyCapsule stream and stream it into unpartitioned tables throughbin_pack_record_batches. That function never split a batch, so a dataframe that exports a single chunk, such as a Polars DataFrame built in one go, ended up in one data file regardless ofwrite.target-file-size-bytes. Converting withpa.table(df)first goes throughbin_pack_arrow_table, which does split by rows.bin_pack_record_batchesnow slices an incoming batch that would push the buffer past the target size, usingRecordBatch.slice(zero copy), so streamed input honors the target file size the same waypa.Tableinput does. The number of rows that fit is found with a binary search over the slice byte size, which also handles variable-width columns. A batch that cannot be sliced to fit, such as a single row larger than the target, is kept whole, and a buffer that reaches the target exactly is flushed before the next input batch is read. The docs note inmkdocs/docs/api.mdthat said a streamed batch is never split has been updated.Are these changes tested?
Yes. Three regression tests were added to
tests/io/test_pyarrow.py:test_bin_pack_record_batches_splits_oversized_batch: a single 10,000-row batch is split into bins at or below the target, and the rebuilt table equals the input.test_bin_pack_record_batches_splits_batch_after_partial_buffer: a large batch arriving after a small one is split across bins, with all rows preserved.test_bin_pack_record_batches_exact_target_flushes_without_reading_ahead: a batch that exactly fills the target is yielded without consuming the next input batch.The new tests fail on the previous implementation and pass with this change. The existing
bin_packand append tests intests/io/test_pyarrow.pyalso pass.Are there any user-facing changes?
Yes. Streamed writes to unpartitioned tables now produce multiple data files sized by
write.target-file-size-bytesinstead of a single file when the input arrives as one large batch. No API changes.