feat(gluten): export a Lance fragment scan as an Arrow C stream - #12
Open
sezruby wants to merge 1 commit into
Open
feat(gluten): export a Lance fragment scan as an Arrow C stream#12sezruby wants to merge 1 commit into
sezruby wants to merge 1 commit into
Conversation
Add LanceArrowStreamScanner, which plans a fragment scan through the existing LanceFragmentScanner and re-exports its ArrowReader as an Arrow C Data Interface stream (ArrowArrayStream). Only the stream's C-struct address crosses the JVM/native boundary, so a native consumer such as Apache Gluten / Velox does not need to match lance-spark's Arrow build or classloader. All scan planning (column projection, filter pushdown, limit/offset, row-id/row-address, batch size) is delegated to LanceFragmentScanner, so the exported stream yields the same rows in the same order as the Spark columnar reader. The returned LanceArrowStream handle owns the exported stream and the scanner behind it; closing it releases the reader (via the C release callback) and then the scanner and dataset. Because exportArrayStream transfers ownership of the reader to the stream, the handle closes only the stream and the scanner, never the reader itself. A follow-up can swap the double-hop for LanceScanner#exportArrowStream(long) once that lands upstream (marked with a TODO); the LanceArrowStream contract is unchanged, so no consumer needs to be touched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Adds
LanceArrowStreamScannerto the base module: it plans a Lance fragment scan through the existingLanceFragmentScannerand re-exports the scan'sArrowReaderas an Arrow C Data Interface stream (ArrowArrayStream).Only the stream's C-struct address (
LanceArrowStream#streamAddress()) crosses the JVM/native boundary, so a native consumer such as Apache Gluten / Velox does not need to match lance-spark's Arrow build or classloader.Why
This is step 2 of the JVM Arrow-in/Arrow-out read path for Gluten support (apache/gluten#12263, Approach 2): lance-spark hands a native engine an Arrow C stream over a planned fragment scan. A gluten-side scan-offload rule that consumes
streamAddress()is the remaining piece.Details
LanceFragmentScanner, so the exported stream yields the same rows in the same order as the Spark columnar reader.LanceArrowStreamhandle owns the exported stream and the scanner behind it.exportArrayStreamtransfers ownership of the reader to the stream, soclose()releases the stream (which closes the reader via the C release callback) and then the scanner and dataset — it never closes the reader itself.TODO(lance#7259)marks a one-line swap toLanceScanner#exportArrowStream(long)once that lands upstream: the Rust core would populate the caller's stream directly and skip the JVM-side Arrow materialization. TheLanceArrowStreamcontract is unchanged, so no consumer needs to be touched.Test
LanceArrowStreamScannerTestexports each fragment of the bundled test table, re-imports it viaData.importArrayStream(standing in for a native consumer), drains it, and asserts the rows match the Spark columnar reader. Closing the imported reader and then the handle under the leak-checkingRootAllocatoralso verifies the export/reader/scanner lifecycle releases cleanly.🤖 Generated with Claude Code