Repository navigation
feat(statement): make execute() the directResults call (Thrift/JDBC model) - #136
Closed
msrathore-db wants to merge 2 commits into
Closed
msrathore-db wants to merge 2 commits into
msrathore-db wants to merge 2 commits into
Conversation
msrathore-db
force-pushed
the
msrathore/sea-execute-directresults
branch
from
June 6, 2026 12:15
db91c25 to
3ee7e54
Compare
msrathore-db
added a commit
to databricks/databricks-sql-nodejs
that referenced
this pull request
Jun 6, 2026
…rives, keep mid-run cancel
The default sync path now calls the kernel's folded directResults `execute()`
(`Connection.executeStatement`, which returns a terminal `Statement` for a fast
query or an `AsyncStatement` for a still-running one). The session
feature-detects the arm via `awaitResult` and wraps it with the operation
backend's existing `statement` / `asyncStatement` arms.
Because the returned handle always corresponds to a server-owned statement:
- fire-and-forget `CREATE`/`INSERT` commits (the server runs it inline during
the POST) — fixes the prior lazy-execute "CREATE didn't run" bug;
- `close()` is a clean release (DELETE), never a drive-to-terminal — the
eager-handle + close-drives workaround is gone;
- a long query is cancellable via `op.cancel()` once the handle is held
(~80-300ms), at parity with the Thrift backend;
- errors surface at `executeStatement`, matching Thrift / Python use_kernel.
Requires the kernel folded directResults execute
(databricks/databricks-sql-kernel#136). Regenerated napi router types
(`executeStatement` now returns `Statement | AsyncStatement`); fallback package
names stay on the driver's canonical `@databricks/sql-kernel-*`.
Validated e2e (pecotesting): CREATE fire-and-forget commits, dependent ordering,
100k read, error-at-execute, mid-run cancel, close() cheap on an abandoned long
query. Unit: SEA suite 247 passing; eslint clean.
Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
…odel)
`Statement::execute()` now sends ExecuteStatement with the server inline wait
(omits `wait_timeout`, so the server applies its ~10s default +
`on_wait_timeout=CONTINUE`) and returns WITHOUT the internal poll loop, handing
back a SINGLE `ExecutedAsyncStatement` (no enum, no caller branching):
- fast query — finished within the inline wait: the handle is seeded with the
inline result (`new_with_inline`), so `status()` reports `Succeeded` and
`await_result()` returns it with ZERO extra round-trips (1 RPC = the POST).
This is the latency fast path and is 404-proof — a terminal handle never
issues GetStatementStatus on a statement the server may have released;
- slow query — still running after the inline wait: an un-seeded poll/cancel
handle the caller drives (`status()` / `await_result()` / `cancel()`).
This is the directResults model JDBC / Thrift / Python `use_sea` use, folded
into `execute()` itself. It gives consumers fire-and-forget commit (the server
runs the statement inline during the POST), a clean non-driving `close()`, and
mid-run cancel (the handle's id is published from the POST response) — without
the eager-handle / close-drives workaround.
A single handle (rather than a blocking drive-to-terminal) is required for
single-threaded callers (napi, the Node driver): the handle must return BEFORE a
long query is terminal so a concurrent `cancel()` can reach it, while a fast
query must commit inline before `close()` races it. The inline-wait POST threads
that needle; JDBC's pure blocking `execute()` works only because it is
multi-threaded. The blocking variant is preserved as `execute_to_completion()`
(returns the eager sync `ExecutedStatement`), so no surface is orphaned.
Auto-close is warehouse-dependent: omitting `wait_timeout` yields `SUCCEEDED` on
some warehouses and `CLOSED` (statement auto-released after delivering its inline
result) on others. A seeded handle maps `CLOSED -> Succeeded` (here CLOSED means
"succeeded and released", result is inline), so directResults behaves identically
across both.
Bindings expose the folded `execute()`: napi `Connection.executeStatement` ->
`AsyncStatement`; pyo3 `Statement.execute` -> `ExecutedAsyncStatement` (with
`execute_to_completion` -> `ExecutedStatement` for the blocking shape).
Replaces the earlier enum (`DirectStatement::Completed | Running`) /
`Either<Statement, AsyncStatement>` design (per review: one handle, not an enum
the caller must branch on). Supersedes #133 (intent-hold).
Tests: fmt + clippy (--all-targets -D warnings) clean; cargo test --lib 620
passed. Validated e2e through both bindings against live warehouses (auto-closing
and non-auto-closing): Node SEA fire-and-forget + fetch 12/12 = Thrift parity, no
close-drive, mid-run cancel; Python use_kernel OK on both.
Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
msrathore-db
force-pushed
the
msrathore/sea-execute-directresults
branch
from
June 6, 2026 14:19
3ee7e54 to
33ce0b6
Compare
msrathore-db
added a commit
to databricks/databricks-sql-nodejs
that referenced
this pull request
Jun 6, 2026
…rives, keep mid-run cancel
The default sync path now calls the kernel's folded directResults `execute()`
(`Connection.executeStatement`), which returns a SINGLE `AsyncStatement` handle.
The session wraps it with the operation backend's existing `asyncStatement` arm —
no arm to feature-detect.
The returned handle always corresponds to a server-owned statement:
- fire-and-forget `CREATE`/`INSERT` commits (the server runs it inline during
the POST) — fixes the prior lazy-execute "CREATE didn't run" bug;
- `close()` is a clean release, never a drive-to-terminal — the eager-handle +
close-drives workaround is gone;
- a long query is cancellable via `op.cancel()` (`asyncStatement.cancel()`)
once the handle is held (~80-300ms), at parity with the Thrift backend;
- errors surface at `executeStatement`, matching Thrift / Python use_kernel.
On the fast path the kernel handle is seeded with the inline result, so the
first fetch/status is served with zero extra round-trips (and is 404-proof — a
terminal handle never polls a released statement). A warehouse that auto-closes
the statement (`state=CLOSED`) after delivering its inline result is handled by
the kernel mapping `CLOSED -> Succeeded`, so this path no longer throws
`OperationStateError(Closed)` on those warehouses.
Requires the kernel folded directResults execute
(databricks/databricks-sql-kernel#136). Regenerated napi router types
(`executeStatement` now returns `AsyncStatement`); fallback package names stay on
the driver's canonical `@databricks/sql-kernel-*`.
Validated e2e (pecotesting) against auto-closing AND non-auto-closing warehouses:
CREATE fire-and-forget commits (12/12 = Thrift parity), fetch-then-close (12/12),
mid-run cancel, close() cheap (~140ms) on an abandoned long query, SELECT 1 p50
179ms vs Thrift 168ms. Unit: SEA suite 247 passing; eslint clean.
Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
msrathore-db
added a commit
to databricks/databricks-sql-python
that referenced
this pull request
Jun 6, 2026
The kernel's `Statement.execute()` is now the directResults call (databricks/databricks-sql-kernel#136): it returns a SINGLE `ExecutedAsyncStatement` -- seeded with the inline result when the query finished within the server inline wait (fast path, zero extra round-trips), or a poll/cancel handle when still running -- instead of always blocking to terminal. `KernelDatabricksClient.execute_command` now drives ONE uniform path (no `hasattr(await_result)` arm to feature-detect): register the handle (so `cursor.cancel()` / `close()` reach it), then `await_result()` to drive it to a ready result set -- preserving execute()'s blocking contract. `cursor.execute()` behaviour is unchanged for callers (still blocks to a ready result set); this just adapts to the kernel's new single-handle return. Mid-run cancel still works via the `_sync_cancellers` canceller registered before execute. Tested e2e against live warehouses (auto-closing and non-auto-closing): SELECT 1, range(N), and CREATE+count all succeed on both. The kernel maps an auto-closed `CLOSED` statement to `Succeeded`, so the connector sees a uniform success regardless of warehouse auto-close behaviour. Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
…rror
`terminal_outcome` rejected a `CLOSED` response that carried no result payload
with `invalid_state("Statement was closed")`. That was both stricter than JDBC
and internally inconsistent with this crate's own `create_reader`, which already
treats `Succeeded | Closed` with no data as a valid EMPTY result set (builds an
`EmptyReader` from the manifest schema).
JDBC's `DatabricksSdkClient` is the reference: it polls while `PENDING`/`RUNNING`
and treats everything else as terminal, with `SUCCEEDED` AND `CLOSED` as the two
success states (`if state != SUCCEEDED && state != CLOSED -> handleFailedExecution`)
— `CLOSED` is the server's auto-close-on-completion signal, common for DDL/DML
and no-row queries that finish and are reaped server-side in one round-trip.
Make `CLOSED` an unconditional terminal success (parity with both JDBC and
`create_reader`): a `CLOSED` response with no result becomes an empty result set
rather than a spurious error. `FAILED` / `CANCELED` remain errors;
`PENDING`/`RUNNING` remain non-terminal. Affects the shared poll path used by
`execute()` and the directResults `execute_direct()`.
Tests: clippy clean; cargo test --lib 620 passed. Re-verified e2e via the Node
binding (CREATE/INSERT fire-and-forget commit, mid-run cancel, no close-drive).
Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
Collaborator
Author
|
Superseded by #140 (additive). The in-place fold here renamed execute()→execute_to_completion and migrated ~50 kernel tests onto it; #140 instead adds execute_direct() alongside an unchanged execute(), so there's no test churn and Python use_kernel needs no change. Same directResults behavior + CLOSED parity. |
This branch was previously 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.
What
Make
Statement::execute()the directResults call (the Thrift / JDBC / Pythonuse_seamodel), returning a singleExecutedAsyncStatement— no enum, no caller branching.execute()sendsExecuteStatementwith the server inline wait (omitswait_timeout, so the server applies its ~10s default +on_wait_timeout=CONTINUE) and returns without the internal poll loop:ExecutedAsyncStatement::new_with_inline).status()reportsSucceededandawait_result()returns the result with zero extra round-trips (1 RPC = the POST). This is the latency fast path and is 404-proof — a terminal handle never issuesGetStatementStatuson a statement the server may have already released.status()/await_result()/cancel()).Why one handle, not an enum or a blocking drive
Single-threaded callers (napi, the Node driver) need the handle back before a long query is terminal so a concurrent
cancel()can reach it — while a fast query must commit inline beforeclose()races it. The inline-wait POST threads exactly that needle. JDBC's pure blockingexecute()works only because it is multi-threaded. The blocking variant is preserved asexecute_to_completion()(returns the eager syncExecutedStatement), so no surface is orphaned.This replaces the earlier enum design (
DirectStatement::Completed | Running/ napiEither<Statement, AsyncStatement>) — per review, one handle the caller never has to branch on.Auto-close is warehouse-dependent
Omitting
wait_timeoutyieldsSUCCEEDEDon some warehouses andCLOSED(statement auto-released after delivering its inline result) on others — verified empirically against two PECOTESTING warehouses. A seeded handle mapsCLOSED → Succeeded(here CLOSED means "succeeded and released", result is inline), so directResults behaves identically across both and downstream consumers never see a spurious closed-state error.Bindings
Connection.executeStatement→AsyncStatementStatement.execute→ExecutedAsyncStatement(plusexecute_to_completion→ExecutedStatementfor the blocking shape)Testing
cargo +stable fmt/cargo clippy --all-targets -D warningsclean;cargo test --lib620 passed.close()~140ms), mid-run cancel; Pythonuse_kernelOK on both.SELECT 1p50 SEA 179ms vs Thrift 168ms.Supersedes #133 (intent-hold). Consumed by databricks/databricks-sql-nodejs#425 and databricks/databricks-sql-python#837.
This pull request and its description were written by Isaac.