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

   <!-- Closes #2680 -->
   <!-- Closes #1655 -->
   
   Closes #2680
   Closes #1655
   
   # Rationale for this change
   
   PyIceberg is coupled to PyArrow at its read/write boundary: `append` / 
`overwrite` reject anything that isn't a `pa.Table` / `pa.RecordBatchReader`, 
and external Arrow consumers can't read a table/scan without `to_arrow()`. 
Users of other Arrow-native libraries (polars, arro3, nanoarrow, …) therefore 
have to convert to PyArrow explicitly.
   
   This PR adopts the [Arrow PyCapsule 
interface](https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html)
 on both sides:
   
   - **Input (#2680):** `append` / `overwrite` accept any object implementing 
`__arrow_c_stream__`, in addition to PyArrow types.
   - **Output (#1655):** `Table` and `DataScan` implement `__arrow_c_stream__`, 
so they can be handed to any Arrow consumer.
   
   ```python
   import polars as pl
   
   df = pl.DataFrame(table.scan())     # read: a scan is an Arrow producer
   table.append(some_polars_frame)     # write: a polars/arro3/… frame is too
   ```
   
   PyArrow inputs are unchanged; other producers are wrapped as a streaming 
`RecordBatchReader`. PyArrow remains an internal write dependency, only the 
caller-side requirement is removed.
   
   Side effect: bin-packing now falls back to referenced buffer size for Arrow 
view types (e.g. `string_view`) that PyArrow can't size via `nbytes`, since 
recent Polars exports produce them.
   
   **Not in scope:**
   
   - `upsert`/`dynamic_partition_overwrite` still require a materialized 
`pa.Table` (they do random access/joins, not streaming).
   - A PyCapsule producer to `append`/`overwrite` on a **partitioned** table 
still raises `NotImplementedError`, the same restriction as 
`pa.RecordBatchReader` today.
   - Materialized `pa.Table` writes are unaffected either way.
   
   ## Are these changes tested?
   
   Yes. `tests/table/test_arrow_capsule.py` (no Docker) covers coercion, 
`append`/`overwrite` across all input forms, the partitioned regression, and 
round-trips through `pa.table()`. `tests/io/test_pyarrow.py` covers the 
`string_view` bin-packing fallback.
   
   ## Are there any user-facing changes?
   
   Yes, additive and backwards compatible. `append`/`overwrite` accept Arrow 
PyCapsule producers; `Table`/`DataScan` implement `__arrow_c_stream__`. No 
change for existing PyArrow inputs.


-- 
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