Skip to content

feat(adbc): add kernel backed Rust ADBC driver - #425

Merged
rahuls-db merged 6 commits into
mainfrom
rahul-singhal_data/feat/rust-adbc
Nov 6, 2026
Merged

rahuls-db merged 6 commits into
mainfrom
rahul-singhal_data/feat/rust-adbc

Conversation

@rahuls-db

@rahuls-db rahuls-db commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

What did you change, and why?

Change: Add adbc/ as a self-contained Cargo workspace that depends on the kernel through its in-repository Rust crate API. It implements ADBC 1.1 through adbc_core, returns Arrow record batches without an IPC or C conversion at the kernel boundary, and optionally builds cdylib/staticlib artifacts exporting both AdbcDatabricksInit and AdbcDriverInit.

Why: Keep the native Rust ADBC driver with the Databricks SQL Kernel it directly builds on in the same repo, so the driver and kernel can evolve through one source and CI boundary. This preserves a native Rust driver-to-kernel path while also providing the standard ADBC C ABI needed by driver managers and other languages.

The driver remains publish = false. This PR adds repository build, formatting, Clippy, test, dynamic-load, package-content, license/advisory, SBOM/OSV, coverage, CODEOWNERS, and integration-test trigger wiring without changing kernel behavior or kernel source.

Dependency note: the ADBC and Arrow crates are the standard public specification/runtime layers needed to expose the ADBC API and Arrow results. Their locked standalone dependency graph is routed through the repository's package proxy and is covered by the existing license, advisory, and SBOM gates.

How do you know it works?

The complete convergence methodology and evidence are recorded in ADBC Buildout — Buildout Convergence Status.

Convergence Loop 1 — C# ADBC vs. Rust ADBC comparator parity

A case passes through exact parity or a predeclared, lossless semantic conversion. Both drivers run the same public operation with the same SQL, effective options, and fixture state. Success/error status, schema, rows, ordering where defined, update counts, lifecycle effects, and required metadata must match after removing diagnostic-only values such as elapsed time, query IDs, and stack traces. Errors compare by semantic ADBC status and SQLSTATE; case-specific exceptions are not allowed.

  • Total: 12,934
  • Parity: 12,921
  • Not applicable: 13 (6 LZ4-disabled, 6 no-CloudFetch, 1 no-CloudFetch-coupled timeout)
  • Mismatch/gap/pending: 0

Convergence Loop 2 — Databricks driver-test specification completeness

Each of the 322 specifications was classified as required, applicable, not applicable, or Post-GA using the ADBC contract, GA milestone, public Rust surface, kernel-path support, and the strongest assertion passing on a comparable kernel-backed driver. Ignored stubs do not count; credential absence remains environment-deferred; driver-side orchestration is required when a comparable kernel driver supplies it; Thrift-only behavior is not a kernel-driver baseline.

  • Applicable: 231
  • Validated: 227
  • Credentialed-CI deferred: 4 (AUTH-004, AUTH-011, AUTH-012, AUTH-013)
  • Failed/timed out: 0
  • Not applicable: 72
  • Post-GA deferred: 19

Convergence Loop 3 — PEC0 ADBC correctness contracts

  • Total: 122
  • Passed: 74
  • Rust-driver failures: 0
  • Shared no-CloudFetch kernel limitation: 31
  • Legacy-HMS/controlled-catalog fixture deferred: 17

All 74 contracts runnable and applicable on the current kernel path pass. By suite: basic connection 1; core 31 plus 31 no-CloudFetch exclusions; BI replay 7; large queries 2; Hive Metastore 1 plus 9 fixture-deferred; all data types 1 plus 2 fixture-deferred; Unity Catalog 8 plus 6 fixture-deferred; stored procedures 23.

Convergence Loop 4 — Reyden GA Scope

Summary

Status Count
Total GA-scope rows 75
Applicable features 58
Fully validated 53
Partially validated 3
Deferred to credentialed CI 2
Not applicable 17

Partially validated — 3

  • OAuth: U2M refresh from an expired encrypted token cache remains.
  • OIDC federation: strict workspace-issued exchanged-token issuer assertion remains.
  • VARCHAR overflow: SEA does not return the expected error for values exceeding VARCHAR(10).

Deferred to credentialed CI — 2

  • Persisted U2M token-cache reopen and refresh.
  • Azure service-principal authentication, including tenant discovery and explicit-tenant flows.

Not applicable — 17

Validation-only gates — 6
  • Small-result single-user latency
  • High-concurrency INLINE_OR_EXTERNAL_LINKS
  • Driver fast path
  • Latency-overhead qualification
  • Port existing tests to databricks-driver-test
  • C# ADBC 8.2-GB SEA performance
Operational/release process — 4
  • Monitoring dashboard setup
  • Nightly-run monitoring
  • Simplified Reyden onboarding
  • Enabling telemetry by default through change management
ODBC-specific — 3
  • OSS ODBC Windows signing
  • OSS ODBC readiness review
  • OSS ODBC large-result performance versus Thrift
Not exposed by ADBC — 3
  • Session-level server statement timeout
  • Async interface
  • Connector-service feature flags
Shared kernel transport validation — 1
  • SEA versus Thrift latency below 5 MB

Repository validation

  • Rust ADBC tests with ffi: 83 passed, 0 failed; 5 explicitly configured live tests ignored.
  • Strict Rust ADBC Clippy with ffi: passed.
  • Release shared library dynamically loaded through AdbcDatabricksInit and AdbcDriverInit; both allocated a database through adbc_driver_manager.
  • Kernel tests: all executed unit, integration, C-ABI, wiremock, and doc tests passed; existing credentialed live tests remained ignored.
  • Kernel strict Clippy: passed.
  • Kernel native C-ABI smoke suite: passed.
  • Root and ADBC rustfmt checks: passed from a clean checkout layout.
  • cargo package --allow-dirty --list: passed with the expected source, docs, tests, examples, and license.
  • Workflow YAML syntax and staged whitespace checks: passed.

cargo-deny is not installed in the local environment; the repository's existing protected-runner license/advisory job is extended to scan the ADBC workspace and remains the authoritative gate.

Follow-ups

  1. Update databricks-driver-test to check out this repository and build adbc/ from source.
  2. Add Rust ADBC as a regular databricks-driver-test CI dimension.
  3. Optionally switch the test integration to a published crate or release artifact after the kernel and driver publication flow exists.

This PR was created with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium · 2 Low

Mostly solid. I found one medium issue: dropping the per-connection Tokio runtime inside an async context will panic, even though the README says calling from inside Tokio is supported. I couldn't review adbc/src/statement.rs or adbc/src/config.rs: the read tool returned nothing for statement.rs, and the diff was cut off before config.rs. Nits: the coverage job runs the ADBC crate without --features ffi, so the C ABI entry points don't count toward coverage, and the README's cargo test --workspace / "workspace fmt" wording suggests the root workspace includes adbc/, which it doesn't.

Other findings

  • 🟡 Medium — Each Connection owns a private multi-thread tokio::runtime::Runtime through an Arc, and Statement, KernelReader, AsyncKernelReader and SequenceReader each hold a clone. block_on_safe covers the block_on calls, but nothing covers dropping the runtime itself. When the last Arc<Runtime> goes away (usually when the Connection or its last reader drops), Runtime::drop shuts down the blocking pool. If that happens on a thread running an async Tokio task, Tokio panics with "Cannot drop a runtime in a context where blocking is not allowed".

A native Rust caller that opens a connection, runs a query and drops everything inside an async fn / #[tokio::main] will hit this panic. The README says that pattern is supported. The runtime.rs tests only exercise block_on_safe and never drop the runtime from inside a caller runtime, so CI won't catch it.

Suggested fix: wrap the runtime in a newtype whose Drop takes the inner Runtime and, when Handle::try_current() succeeds, calls shutdown_background() (or moves the drop to a helper thread). Then add a test that drops a Connection/runtime inside both current-thread and multi-thread caller runtimes.

  • 🔵 Low — Database::open builds a new default new_multi_thread() runtime for every connection. The default starts one worker thread per CPU core plus a blocking pool, so N connections create about N × cores OS threads. With the high-concurrency benchmark defaults (16 connections) on a 32-core host, that is over 500 idle worker threads, and connection pools in BI tools will grow the same way. Consider sharing one runtime across a Database's connections, or capping worker_threads for the per-connection runtime.

Comment thread Makefile Resolved
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
@rahuls-db
rahuls-db force-pushed the rahul-singhal_data/feat/rust-adbc branch from f415a74 to 766220d Compare November 5, 2026 23:17
@rahuls-db rahuls-db changed the title feat(adbc): add native Rust ADBC driver feat(adbc): add kernel backed Rust ADBC driver Nov 5, 2026

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium · 2 Low

Mostly solid, with 1 medium concern: the C entry point rejects ADBC 1.0.0 initialization. Runtime bridging, cancellation, and the CI wiring look carefully designed. The two low findings cover cleanup consistency in the synchronous reader and local lint coverage of the ffi feature.

Other findings

  • 🟡 Medium — initialize_ffi_driver sends back NotImplemented for any version other than ADBC_VERSION_1_1_0. That includes ADBC_VERSION_1_0_0. Under the ADBC C API, a driver that supports a newer version should still fill in the older, smaller AdbcDriver struct when a driver manager or binding asks for 1.0.0. Right now any consumer that loads with 1.0.0 cannot use this driver at all, even though every 1.0 entry point is implemented.

Suggested fix: accept V100 too, and for that version copy only the 1.0 prefix of FFI_AdbcDriver, so nothing is written past the caller's smaller allocation. Then add a case to ffi_cancel_methods_use_safe_not_implemented_fallbacks (or a new test) that asserts V100 initialization succeeds.

  • 🔵 Low — When the result is fully read (Ok(None)), KernelReader::next calls finish() but never self.close(). AsyncKernelReader (L412) does close in the same case. Because finish() sets done, KernelReader::drop also skips cancel_and_close. Server-side cleanup for a fully read synchronous result is therefore left to the kernel's fire-and-forget ExecutedStatement::Drop.

The risk is when the reader holds the last Arc<RuntimeHandle>, for example after the connection has already been dropped. In that case the owned runtime is dropped right after executed, and its shutdown_background() can abort the spawned CloseStatement task before it runs. That would leak the server statement.

Suggested fix: call self.close() in the Ok(None) arm, matching the async reader, so cleanup is deterministic on every path.

Comment thread Makefile Resolved
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Low

Looks solid overall. I found two low-severity issues: three result readers don't clean up after a batch fails schema normalization, and the benchmark reports hard-code the kernel version. The runtime bridging, cancellation registry, FFI init (1.0 prefix copy, cancel slots set to null) and CI wiring all look correct and are well tested.

Other findings

  • 🔵 Low — If normalize_result_batch returns Err (for example a batch whose schema differs from the advertised schema), next() gives the error back but does not set lifecycle.done. It also does not release the connection operation guard or close the server statement. A caller that keeps iterating after the error will keep pulling batches. Meanwhile Connection::cancel still sees the operation as active, so it can cancel a result that has already failed. The other error arms (Ok(Some(_)), Err(source)) all call finish() and close() first.

The same pattern appears in AsyncKernelReader::next (line 404) and SequenceReader::next (line 538, which could route through self.fail(...)). Suggested fix: match on the normalized result and on Err call self.finish(); self.close(); before returning, as the sibling arms do. A unit test with a mismatched-schema batch would cover this.

Comment thread adbc/examples/benchmark.rs Resolved
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Low

Looks reasonable: CI, deny, SBOM and coverage now include the standalone adbc/ workspace, and the FFI init's version-sized copy is tested. Two low findings: connection-level cancellation registrations that nothing can ever trigger, and connection/reader Drop impls that block without a time limit. I could only partly review the large config.rs and statement.rs because the diff and file reads were truncated.

Other findings

  • 🔵 Low — execute_session_command and current_namespace register a cancel callback in the connection's CancellationRegistry, but nothing can reach that callback while either function runs. Connection::cancel takes &mut self, Connection isn't Clone, and no public handle exposes self.cancellation. Safe Rust therefore can't call cancel() while set_option(CurrentCatalog/Schema) or get_option_string(CurrentCatalog/Schema) holds the borrow. The C ABI also nulls out ConnectionCancel. So these two registrations, about 30 duplicated lines including the "raced before the server statement identifier" error path, never run. This also contradicts the README's claim that native Rust connection cancellation covers these operations.

Fix options:

  • Expose a Connection::cancellation_handle() like Statement::cancellation_handle(), so the registration actually does something.
  • Or drop the registration and pull the duplicated closure into one helper.
  • 🔵 Low — Drop for Connection blocks with no time limit on session.close() and throws away the result (let _ =). When dropped from a Tokio multi-thread worker, this goes through block_in_place. If DeleteSession hangs (network partition, proxy stall), dropping the connection stalls the caller's thread for as long as the kernel's HTTP/retry budget lasts, and nothing is logged. The reader Drop impls (cancel_and_close, reader.rs:335/442/608) do the same thing with two sequential round-trips.

Suggested fix:

  • Wrap the close in tokio::time::timeout.
  • Emit a tracing warning when the close fails, so cleanup failures are visible.

Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 2 Low

Looks good overall, with two low-severity cleanups. The parts I could read are carefully built: runtime bridging (block_on_safe), field drop order for runtime and reader cleanup, null FFI cancel slots, and the V1.0 prefix-only init. I couldn't review statement.rs and config.rs in full because they were cut off by the size cap.

Other findings

  • 🔵 Low — execute_session_command and current_namespace each contain an identical copy of the cancellation callback: block_on_safe(canceller.cancel()), then a fallback when the cancel wasn't dispatched, with the same "raced before the server statement identifier" message. Move it into a small helper, such as fn register_statement_cancel(&self, canceller, runtime) -> Result<OperationGuard>. That way the two connection-scoped commands can't drift apart if the race handling or status mapping changes later.

Comment thread Makefile Resolved

This branch was previously deployed

1 inactive deployment
azure-prod — 1c28540b Deployed Nov 6, 2026 by oss-reviewer-bot[bot] via followup #2168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants