Repository navigation
[WIP][SQL] Prototype a Rust SDK for native batch data sources - #59442
Draft
gengliangwang wants to merge 2 commits into
Draft
gengliangwang wants to merge 2 commits into
gengliangwang wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Important
Updated Rust SDK: #59520 is the companion SDK for the FFM/C ABI in #59424. It adds an explicit serializable reader factory, cooperative task cancellation, and batch-only capabilities.
This PR contains the earlier JNI prototype targeting #59313. Please direct further SDK development and review to #59520.
What changes were proposed in this pull request?
Add a standalone Rust SDK prototype for batch reads under
sql/native/rust,with a separate Range connector under
examples/src/main/rust/native-data-source.The Cargo workspace and lockfile live with the SDK. The example is a workspace
member that depends on the SDK through a Cargo path dependency.
Connector authors implement
BatchSourceandScanBuilder, return ordinary ArrowRecordBatchReaderinstances, and register the provider withexport_data_source!(RangeSource). The SDK handles JNI exports, native handles,typed plan serialization, errors, and Arrow C Stream ownership. Rust traits stay
inside the plugin; they are not a cross-library Rust ABI.
The prototype includes:
Exact,PruningOnly, andUnsupportedresults; globalversus per-partition limit support; and top-level column projection. The bridge
declines limit pushdown when filters remain residual.
filter pushdown, global limits, and empty/reordered projections.
.sparkpkgpackaging helper, a Spark smoke script, and build/API documentation.Runtime dependency: the adapter targets the batch JNI ABI from #59313 at
ff7b1ae0150fbcb3b6a7c67bea8accf6aa4ad9bd. This PR does not include that framework.Running the connector in Spark requires a distribution containing it. The
standalone Rust and JNI tests do not require building Spark.
This draft is intended to evaluate a connector-facing SDK on top of the proposed
native protocol. It does not establish a stable SDK or modify Spark's Maven/SBT
build. Writes, Structured Streaming, C++ bindings, cancellation, and Spark memory
accounting are outside this demo's scope. The README documents the pinned
framework's Arrow layout restrictions and the remaining integration work.
Why are the changes needed?
Implementing native connectors directly against JNI requires each connector to
repeat handle management, plan serialization, error conversion, and Arrow
lifecycle code. A Rust SDK lets connector authors focus on planning and reading
while making pushdown semantics explicit. This working prototype gives reviewers
a concrete API and connector to evaluate alongside #59313.
Does this PR introduce any user-facing change?
It adds an opt-in example and experimental Rust API. There is no change to Spark's
built-in data sources or default build, and no published crate or compatibility
commitment. With the required framework, the packaged example can be loaded via
spark.addArtifact(...)andspark.read.format("rust_sdk_range").load().How was this patch tested?
From
sql/native/rust, using Rust 1.89.0 and JDK 17:cargo build --workspace --locked cargo test --workspace --locked cargo clippy --workspace --all-targets --locked -- -D warnings cargo fmt --all -- --check python3 ../../../examples/src/main/rust/native-data-source/package.py \ --library target/debug/libspark_datasource_rust_sdk_range.so \ --output target/rust_sdk_range.sparkpkgAll 19 tests passed: 18 Rust unit tests and one integration test that compiles a
minimal Java fixture, starts a real JVM with
-Xcheck:jni, loads the connectorshared library, and consumes its Arrow C Stream. Coverage includes serialized
plans, exact/residual filters, limits, empty projections, integer boundaries,
retained batch ownership after stream release, and provider errors/panics.
Also checked the package manifest and embedded library bytes, Python script
syntax, license headers, formatting, and whitespace.
The Spark smoke script is provided but was not run: the current worktree is
based on master and does not contain #59313. The JNI fixture tests are not full
Spark integration tests. Full Spark builds and Apache RAT were not run.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6)