Repository navigation
feat: zero-copy Arrow C Data Interface at the Python/Rust boundary - #13
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The FFI ownership handling is sound and the new behavior has comprehensive parity and edge-case coverage.
0 open findings
What changed in this PR
Replaces Arrow IPC serialization at the Python/Rust boundary with the Arrow C Data Interface while retaining an IPC fallback.
Changes:
- Adds zero-copy stream conversion and capsule lifecycle handling.
- Raises minimum PyArrow to 15 and enables Arrow FFI.
- Adds parity tests and a boundary benchmark.
| File | Description |
|---|---|
src/lib.rs |
Implements C stream transfers and IPC fallback. |
tests/test_ggsql.py |
Tests both boundary modes and edge cases. |
scripts/bench_arrow_boundary.py |
Benchmarks stream versus IPC transfers. |
Cargo.toml |
Enables Arrow’s FFI feature. |
pyproject.toml |
Raises the minimum PyArrow version. |
uv.lock |
Records updated PyArrow constraints. |
CHANGELOG.md |
Documents the new transfer path and fallback. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cpsievert
force-pushed
the
feat/arrow-zero-copy
branch
from
October 13, 2026 18:41
5e6e8f2 to
9caae63
Compare
cpsievert
marked this pull request as ready for review
October 13, 2026 19:04
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.
Summary
py_to_df()/df_to_py()insrc/lib.rs, so there are no signature changes — those two functions are now dispatchers.GGSQL_ARROW_IPC=1as an escape hatch (e.g., for exotic types that fail to round-trip through the C stream).arrow::ffi_streamwas chosen over thearrow-pyarrowcrate: arrow-pyarrow 58 requires pyo3 0.28 (this crate is on 0.26), and arrow-pyarrow 57.x pins arrow-array 57 (incompatible with ggsql's arrow-58DataFrametypes). A pyo3 upgrade can happen later on its own merits.RecordBatchReader.from_streamconsumption API landed in 15.0; 14 only has the export side). Thearrowcrate dependency gains itsffifeature.df_to_py): theRecordBatchis wrapped in anFFI_ArrowArrayStream, exported as aPyCapsulewith a C Data Interface-correct destructor, and consumed via a small#[pyclass]shim exposing__arrow_c_stream__()→pa.RecordBatchReader.from_stream(...).read_all().py_to_df, the hot path):table.__arrow_c_stream__()→ArrowArrayStreamReader::from_raw→concat_batches, with the same empty-table semantics as the IPC path.Verification
uv run pytest tests/with and withoutGGSQL_ARROW_IPC=1(136 passed, 5 skipped in each), including 15 new edge-case/parity tests (dictionary-encoded columns, timestamps with timezones, empty results, chunked multi-batch tables, nullable columns, extension types, IPC-fallback smoke test).cargo fmt -- --checkandcargo clippy -- -D warningsare clean.ru_maxrss(Δ ~1 MB).SELECT *; script below, deliberately not committed): zero-copy stream 17.5s / 3246 MB peak RSS vs IPC 99.2s / 4247 MB — ~5.7× faster with ~1 GB lower peak RSS. Note DuckDB ArrowVTab ingestion (2048-row chunks) is a constant cost in both modes; the delta isolates the boundary savings.Benchmark script (run with
uv run python bench_arrow_boundary.py)