feat(java): expose ArrowArrayStream export on LanceScanner#7259
Open
sezruby wants to merge 2 commits into
Open
feat(java): expose ArrowArrayStream export on LanceScanner#7259sezruby wants to merge 2 commits into
sezruby wants to merge 2 commits into
Conversation
Add public LanceScanner#exportArrowStream(ArrowArrayStream) wrapping the existing private native openStream(long) call. Lets callers populate a stream they allocated themselves (typically from their own BufferAllocator) instead of going through scanBatches(), which immediately imports into a Java ArrowReader backed by Lance's allocator. The motivation is consumers loaded under a different classloader / pinned to a different Apache Arrow version. Sharing org.apache.arrow.vector.* classes across classloader boundaries is not safe, but the C Data Interface struct is stable across Arrow versions — so handing the C struct's memory address through is the only correct integration boundary. A concrete consumer is the ongoing gluten-spark/Velox integration tracked at apache/gluten#12263, which needs to import Lance scan output into its own Arrow 15 + Velox runtime; gluten-spark is built against Arrow 15 while Lance is on Arrow 18. Test exercises the full path end-to-end: caller allocates a stream from its own RootAllocator, scanner fills the C struct, caller imports into an ArrowReader and validates batch contents.
Contributor
Author
|
@hamersaw @jackye1995 Could you review the PR? The PR is to support Lance Reader in Gluten/Spark. I'll open a lance-spark PR after this PR is merged. Thanks! |
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
Add
LanceScanner#exportArrowStream(ArrowArrayStream)— a public wrapper around the existing private nativeopenStream(long)JNI call. Lets callers populate a stream they allocated themselves instead of going throughscanBatches(), which immediately imports the result into a JavaArrowReaderbacked by Lance'sBufferAllocator.Why
Consumers loaded under a different classloader and/or pinned to a different Apache Arrow version cannot safely share
org.apache.arrow.vector.*classes with Lance — the JVM treats them as distinct types even when the bytecode is identical. The C Data Interface struct is stable across Arrow versions, so handing the C struct's memory address across the boundary is the only correct integration shape.A concrete consumer is the gluten-spark / Velox integration tracked at apache/gluten#12263. gluten-spark builds against Arrow 15 (matching what Spark 3.5 ships and Velox uses); Lance Java SDK is on Arrow 18. With this method, gluten can:
…where
glutenAllocatoris a Spark-task-managedBufferAllocator(ArrowReservationListenerplumbing for memory accounting). Lance never sees Java Arrow on this side; ownership stays with the caller via the C Data Interface release callback.What changed
LanceScanner#exportArrowStream(ArrowArrayStream)— new public method, ~7 lines + Javadoc with usage example. Mirrors the body ofscanBatches()minus the local stream allocation and theData.importArrayStreamstep.testDatasetScannerExportArrowStreamexercises the full path: caller allocates the C stream from its ownRootAllocator, scanner fills the C struct, caller imports into anArrowReaderand validates batch contents (40 rows over 2 batches of 20).Backwards compatibility
Pure addition.
scanBatches(),schema(),countRows(),getStats(),close()all unchanged. No native ABI change.Test plan
./mvnw test -Dtest=ScannerTest#testDatasetScannerExportArrowStream— passes locally (Java compile + spotless clean; full test run depends on a workinglance-jniRust build, which had an unrelatedaws-smithy-typesregistry issue on my machine, so I'm relying on CI for the JNI-linked verification).testDatasetScannerColumnscovers thescanBatches()path so any regression in the sharedopenStreamJNI call would surface there.