Repository navigation
feat(adbc): add kernel backed Rust ADBC driver - #425
Conversation
There was a problem hiding this comment.
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
Connectionowns a private multi-threadtokio::runtime::Runtimethrough anArc, andStatement,KernelReader,AsyncKernelReaderandSequenceReadereach hold a clone.block_on_safecovers theblock_oncalls, but nothing covers dropping the runtime itself. When the lastArc<Runtime>goes away (usually when theConnectionor its last reader drops),Runtime::dropshuts 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::openbuilds a new defaultnew_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 aDatabase's connections, or cappingworker_threadsfor the per-connection runtime.
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
f415a74 to
766220d
Compare
There was a problem hiding this comment.
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_driversends backNotImplementedfor any version other thanADBC_VERSION_1_1_0. That includesADBC_VERSION_1_0_0. Under the ADBC C API, a driver that supports a newer version should still fill in the older, smallerAdbcDriverstruct 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::nextcallsfinish()but neverself.close().AsyncKernelReader(L412) does close in the same case. Becausefinish()setsdone,KernelReader::dropalso skipscancel_and_close. Server-side cleanup for a fully read synchronous result is therefore left to the kernel's fire-and-forgetExecutedStatement::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.
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
There was a problem hiding this comment.
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_batchreturnsErr(for example a batch whose schema differs from the advertised schema),next()gives the error back but does not setlifecycle.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. MeanwhileConnection::cancelstill sees the operation as active, so it can cancel a result that has already failed. The other error arms (Ok(Some(_)),Err(source)) all callfinish()andclose()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.
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
There was a problem hiding this comment.
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_commandandcurrent_namespaceregister a cancel callback in the connection'sCancellationRegistry, but nothing can reach that callback while either function runs.Connection::canceltakes&mut self,Connectionisn'tClone, and no public handle exposesself.cancellation. Safe Rust therefore can't callcancel()whileset_option(CurrentCatalog/Schema)orget_option_string(CurrentCatalog/Schema)holds the borrow. The C ABI also nulls outConnectionCancel. 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()likeStatement::cancellation_handle(), so the registration actually does something. - Or drop the registration and pull the duplicated closure into one helper.
- 🔵 Low —
Drop for Connectionblocks with no time limit onsession.close()and throws away the result (let _ =). When dropped from a Tokio multi-thread worker, this goes throughblock_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 readerDropimpls (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
tracingwarning when the close fails, so cleanup failures are visible.
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>
There was a problem hiding this comment.
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_commandandcurrent_namespaceeach 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 asfn 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.
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 throughadbc_core, returns Arrow record batches without an IPC or C conversion at the kernel boundary, and optionally buildscdylib/staticlibartifacts exporting bothAdbcDatabricksInitandAdbcDriverInit.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.
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.
AUTH-004,AUTH-011,AUTH-012,AUTH-013)Convergence Loop 3 — PEC0 ADBC correctness contracts
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
Partially validated — 3
VARCHAR(10).Deferred to credentialed CI — 2
Not applicable — 17
Validation-only gates — 6
INLINE_OR_EXTERNAL_LINKSdatabricks-driver-testOperational/release process — 4
ODBC-specific — 3
Not exposed by ADBC — 3
Shared kernel transport validation — 1
Repository validation
ffi: 83 passed, 0 failed; 5 explicitly configured live tests ignored.ffi: passed.AdbcDatabricksInitandAdbcDriverInit; both allocated a database throughadbc_driver_manager.cargo package --allow-dirty --list: passed with the expected source, docs, tests, examples, and license.cargo-denyis 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
databricks-driver-testto check out this repository and buildadbc/from source.databricks-driver-testCI dimension.This PR was created with GitHub MCP.