Skip to content

to_arrow_reader() and the Arrow C Stream interface on both builds - #574

Merged
tae898 merged 3 commits into
mainfrom
feat/322-arrow-reader
Dec 4, 2026
Merged

tae898 merged 3 commits into
mainfrom
feat/322-arrow-reader

Conversation

@tae898

@tae898 tae898 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds to_arrow_reader(batch_size, columns) to the result of both packages. It returns a pyarrow.RecordBatchReader with one record batch per column frame (at most batch_size rows), and a frame is read from the engine only when its batch is asked for, so a large result no longer has to fit in memory as one table. The result also implements __arrow_c_stream__, so pyarrow.table(result) and polars.DataFrame(result) read it through the reader.

The schema of a reader is fixed before its first batch, so it is the schema of the first batch, where to_arrow() sees every batch before it picks one type. A later batch that lacks a column adds nulls, and a value that converts without loss is converted. A column that first appears in a later batch, or a value that does not convert, raises ArcadeDBError that names the column and points to to_arrow(). A result is a cursor, so it is read once. DuckDB asks an object for its stream more than once, so it reads the reader (SELECT ... FROM reader) and not the result; the page says so and a test pins it.

The frame loops of both packages moved into generators (_arrow_frames on the JVM package, _frames on the native one) that to_arrow() and to_columns() use too, so there is one read loop for each.

Related issues

Closes #322

Performance changes

Not measured. The issue asks for the peak memory of a 10M-row read, to_arrow() against the reader, per phase from the cgroup. That is a timed run and waits for the 26.12.1 wheels and a bench host. This PR states no speed or memory figure.

Docs

how-to/dataframes-and-columns.adoc: new section "Read a large result in batches".

Checklist

  • A regression test fails on the old code and passes on the new (tests/test_resultset_arrow_reader.py: the method does not exist on main; 12 tests pass on both packages)
  • The test suite that the change can affect passes (see the checks)
  • uvx pre-commit run --files <changed files> passes

…hReader with one batch per frame, the schema of the first batch (#322)
…s from the reader and closes the result (the test #331 left open)
…frame; the reader test closes the database mid-read instead of relying on an engine error
@tae898
tae898 merged commit 8f43af7 into main Dec 4, 2026
26 checks passed
@tae898
tae898 deleted the feat/322-arrow-reader branch December 4, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Both wheels: a batched Arrow reader and the Arrow C Stream interface (to_arrow_reader, __arrow_c_stream__)

1 participant