PCTEJA opened a new pull request, #4505:
URL: https://github.com/apache/iceberg-python/pull/4505

   <!-- Closes #4499 -->
   
   # Rationale for this change
   
   Since #3447, `tbl.append()` and `tbl.overwrite()` accept any Arrow PyCapsule 
stream and stream it into unpartitioned tables through 
`bin_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 of `write.target-file-size-bytes`. Converting 
with `pa.table(df)` first goes through `bin_pack_arrow_table`, which does split 
by rows.
   
   `bin_pack_record_batches` now slices an incoming batch that would push the 
buffer past the target size, using `RecordBatch.slice` (zero copy), so streamed 
input honors the target file size the same way `pa.Table` input 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 in `mkdocs/docs/api.md` that 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_pack` and append tests in `tests/io/test_pyarrow.py` also 
pass.
   
   ## Are there any user-facing changes?
   
   Yes. Streamed writes to unpartitioned tables now produce multiple data files 
sized by `write.target-file-size-bytes` instead of a single file when the input 
arrives as one large batch. No API changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to