Repository navigation
feat(python): support streaming SQL results - #1103
Merged
Merged
Conversation
plusplusjiajia
force-pushed
the
feat/python-sql-stream
branch
3 times, most recently
from
October 11, 2026 11:12
05cd430 to
0102091
Compare
plusplusjiajia
force-pushed
the
feat/python-sql-stream
branch
from
October 11, 2026 11:39
0102091 to
bd59037
Compare
plusplusjiajia
marked this pull request as ready for review
October 11, 2026 12:01
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.
Purpose
Linked issue: N/A.
Python
SQLContext.sql()andsql_with_options()collect all result batches before returning. Addsql_stream()andsql_stream_with_options()so callers can consume PyArrow batches incrementally and stop reading early.Brief change log
RecordBatchReaderfrom DataFusion's execution stream, preserving SQL error conversion and PyArrow string compatibility.INSERTandCOPY, including underEXPLAIN ANALYZE, before returning. DataFusion runs them only while the result is polled, so a reader closed unread would otherwise skip the write.RecordBatchReader.schema, so an empty result keeps its column names and types.SQLOptionsrestrictions.Tests
test_sql_stream.py,test_datafusion.py, andtest_read.py, using CPython 3.10 and locally generated filesystem Paimon fixtures.cargo test --locked -p pypaimon_rust --lib, including pending-read cancellation and stream cleanup, using an embedded CPython 3.11 interpreter.cargo clippy --locked -p pypaimon_rust --all-targets --no-deps -- -D warnings.cargo fmt --all -- --checkandgit diff --check.API and Format
Adds
SQLContext.sql_stream(sql)andSQLContext.sql_stream_with_options(sql, options), both returningRecordBatchReader. AddsRecordBatchReader.schema, which is the PyArrow result schema for SQL streams andNonefor table reads.Existing readers shared by
TableRead.read_arrow()and shard updates now release their stream on EOF or an underlying read error. The failing read raises the error; subsequent reads returnNone. Callers must create a new reader to retry.The binding avoids collecting the entire output, while operators such as sorting and aggregation may still buffer data. No storage format changes.
Documentation
Adds Python type stubs and a README example using
contextlib.closingto release the reader when iteration stops early. The README notes thatSQLOptionsrestrict statements delegated to DataFusion, as insql_with_options(), but not statements Paimon handles itself, such asDELETE,UPDATE,MERGE INTOorDROP TABLEon a Paimon table.