Skip to content

feat(pyo3): async statement (submit / status / await_result / fetch_result) - #15

Closed
vikrantpuppala wants to merge 1 commit into
feat/pyo3-metadatafrom
feat/pyo3-async-statement
Closed

vikrantpuppala wants to merge 1 commit into
feat/pyo3-metadatafrom
feat/pyo3-async-statement

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Stacks on #14 (metadata + ResultStream), which stacks on #13 (PyO3 scaffold). Review/merge those first.

Summary

  • Phase 1 step 4 of the PySQL × kernel integration plan.
  • Wraps the kernel's `ExecutedAsyncStatement` so the connector can run `cursor.execute(async_op=True)` workflows through the kernel: `submit` returns immediately with a `statement_id`, the caller polls `status()` and pulls results via `await_result()` / `fetch_result()`.

Surface added

Python Returns
`Statement.submit()` `ExecutedAsyncStatement`
`ExecutedAsyncStatement.statement_id` str
`ExecutedAsyncStatement.status()` `(state: str, failure: Optional[dict])`
`ExecutedAsyncStatement.await_result()` `ResultStream`
`ExecutedAsyncStatement.fetch_result()` `ResultStream`
`ExecutedAsyncStatement.cancel() / close()` —

`state` is one of `Pending / Running / Succeeded / Failed / Cancelled / Closed`. For `Failed`, `failure` carries the same structured-attrs dict `KernelError` exposes (`code`, `message`, `sql_state`, `error_code`, `vendor_code`, `http_status`, `retryable`, `query_id`). Returning the dict rather than raising lets polling callers branch without a try/except boundary; the connector backend re-raises to PEP 249 exceptions when it actually needs to.

Test plan

  • `cargo build --workspace`
  • `cargo clippy --workspace --all-targets -- -D warnings`
  • `cargo +stable fmt --all -- --check`
  • `cargo test --workspace`
  • Live smoke test against dogfood — extended `pyo3/smoke.py` with: `submit + await_result` round-trip (SELECT 7 → 1 row, terminal status after await), `submit + status-loop + fetch_result` (SELECT 99), `submit` against bad SQL → terminal status `Failed` with the full structured failure dict (`code='SqlError', sql_state='42P01', error_code='BAD_REQUEST', query_id=...`), and use-after-close. All checks pass.

This pull request and its description were written by Isaac.

…esult)

Phase 1 step 4. Wraps the kernel's `ExecutedAsyncStatement` so the
connector can run `cursor.execute(async_op=True)` workflows through
the kernel: submit returns immediately with a `statement_id`, the
caller polls `status()` and pulls results via `await_result()` or
`fetch_result()` once a terminal state is reached.

New Python surface:

- `Statement.submit() -> ExecutedAsyncStatement`
- `ExecutedAsyncStatement.statement_id`
- `ExecutedAsyncStatement.status() -> (state: str, failure: Optional[dict])`
  Returns one of `Pending / Running / Succeeded / Failed / Cancelled
  / Closed`. `failure` is populated only for `Failed` and carries the
  same structured-attrs dict that `KernelError` exposes (code,
  sql_state, error_code, query_id, etc.). Surfacing failure as a
  dict rather than raising lets polling callers branch without a
  try/except boundary.
- `ExecutedAsyncStatement.await_result() -> ResultStream` — blocks
  with kernel-managed poll cadence, raises on `Failed` / `Cancelled`.
- `ExecutedAsyncStatement.fetch_result() -> ResultStream` — fetches
  without polling; raises `KernelError(code='InvalidState')` if the
  statement is still running.
- `ExecutedAsyncStatement.cancel() / close()` — same semantics as
  the sync handle's counterparts.

Smoke test (`pyo3/smoke.py`) extended with the async surface; all
checks pass against dogfood.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala

Copy link
Copy Markdown
Collaborator Author

Collapsed into #13 — that PR now carries all four Phase 1 commits (scaffold, metadata, async, external auth) as a single review. Closing this one to consolidate the review.

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