Skip to content

feat(c-abi): wire async submit/poll/cancel + init_logging - #161

Closed
mani-mathur-arch wants to merge 1 commit into
mainfrom
mani/c-abi-async-statement
Closed

mani-mathur-arch wants to merge 1 commit into
mainfrom
mani/c-abi-async-statement

Conversation

@mani-mathur-arch

Copy link
Copy Markdown
Contributor

What

Implements the async statement path over the C ABI, which PR #158 left as a stub returning InvalidArgument. Rust-crate consumers (PyO3/napi) already drive Statement::submit + ExecutedAsyncStatement directly; this exposes the same lifecycle to C-ABI consumers (Go's database/sql, ODBC) that cannot link the Rust crate.

New C entry points (declared in include/databricks_kernel.h):

  • kernel_statement_submit — submit for async execution, returns an ExecutedAsyncStatement-backed handle.
  • kernel_executed_async_statement_status — poll server-side status, mapping StatementStatus → KernelStatementStatusKind. A Failed status stores the underlying error for kernel_get_last_error while the poll call itself returns Success.
  • kernel_executed_async_statement_get_result_stream — fetch the result once terminal-succeeded, returned as a new OwnedLazy result-stream variant that owns the ResultStream and drives it one batch per next_batch, so CloudFetch chunks stream on demand rather than materialising up front (unlike the bounded metadata Owned path, which pre-drains).
  • kernel_executed_async_statement_cancel / _close.

This is the path a host driver uses to honor caller-side context cancellation/deadlines — the consumer polls status while sleeping between polls (holding no server-side worker thread) and calls _cancel on the caller's cancel/deadline signal, giving parity with a Thrift backend's poll + CancelOperation.

Also wires crate::logging::init_logging into the C-ABI runtime() funnel. RUST_LOG was previously a no-op for C-ABI consumers, since they install no Rust-side subscriber and never reach the Rust-native init path; runtime() is the funnel every async entry point passes through, so initialising there (idempotent via the logging module's OnceLock) surfaces RUST_LOG=databricks_sql_kernel=debug for Go/ODBC.

Testing

  • cargo test — 676 lib tests pass, 0 failed.
  • cargo clippy --all-targets -- -D warnings — clean.
  • cargo +stable fmt --all -- --check — clean.
  • Added null-guard unit tests for each async entry point (null handle / null out-param → InvalidArgument, never a crash/deref); the server-driven happy paths are covered by the existing e2e/wiremock integration tests.
  • Additive to the merged sync C ABI: sync next_batch / get_schema signatures are unchanged, so this is ABI-compatible with the sync path.

Implement the async statement path over the C ABI, previously a stub
returning InvalidArgument:

- kernel_statement_submit: submit for async execution, return an
  ExecutedAsyncStatement-backed handle.
- kernel_executed_async_statement_status: poll server-side status,
  mapping StatementStatus to KernelStatementStatusKind; a Failed status
  stores the underlying error for kernel_get_last_error while the poll
  call itself returns Success.
- kernel_executed_async_statement_get_result_stream: fetch the result
  once terminal-succeeded, returned as a new OwnedLazy result-stream
  variant that owns the ResultStream and drives it one batch per
  next_batch call, so CloudFetch chunks stream on demand rather than
  materialising up front (unlike the metadata Owned path).
- kernel_executed_async_statement_cancel / _close.

This is the path a host driver (Go database/sql) uses to honor
caller-side context cancellation/deadlines, giving parity with the
Thrift backend's poll + CancelOperation.

Also wire crate::logging::init_logging into the C-ABI runtime() funnel:
RUST_LOG was a no-op for C-ABI (Go/ODBC) consumers that install no
Rust-side subscriber, since they never call the Rust-native init path.

Update include/databricks_kernel.h with the four new declarations and
correct the stale "deferred in v0" comments. Add null-guard unit tests
for each async entry point; the server-driven paths are covered by the
e2e/wiremock integration tests.

Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
@mani-mathur-arch

Copy link
Copy Markdown
Contributor Author

superseded

This branch was previously deployed

1 inactive deployment
azure-prod — 2b686562 Deployed Jul 5, 2026 by mani-mathur-arch via v0 TLS (mitmproxy) #191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant