Skip to content

feat(statement,napi): surface row_limit + per-statement query timeout on StatementSpec - #94

Closed
msrathore-db wants to merge 2 commits into
msrathore/krn-statement-optionsfrom
msrathore/krn-statement-row-limit-timeout
Closed

msrathore-db wants to merge 2 commits into
msrathore/krn-statement-optionsfrom
msrathore/krn-statement-row-limit-timeout

Conversation

@msrathore-db

@msrathore-db msrathore-db commented May 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Surfaces two per-statement options that the SEA wire already supports but the public StatementSpec did not expose — closing parity-matrix rows 2.15 (row_limit) and 2.17 (server statement timeout). Both are offered today by Python use_sea (row_limit=, wait_timeout=); without this, NodeJS SEA and Python use_kernel (both routed through this kernel) cannot match the Thrift/Python surface.

This is the follow-on the statement-options ExecuteOptions doc explicitly deferred (row_limit/wait_timeout "land in follow-on PRs").

Changes

  • StatementSpec gains row_limit: Option<i64> and query_timeout_secs: Option<u32> with fluent setters. No new wire surface — types::sea::ExecuteParams already carried row_limit / wait_timeout / on_wait_timeout; this threads the spec values through prepare_for_dispatch.
  • Server statement timeout maps to SEA wait_timeout with on_wait_timeout = CANCEL, so the statement is cancelled on elapse (JDBC setQueryTimeout / Python use_sea wait_timeout semantics) — distinct from the connection-level transport overall_timeout.
  • The wait-timeout precedence (async-submit "0s" respected verbatim · sync-execute honoring the spec timeout · server default when neither set) is extracted into a pure resolve_wait_timeout helper and unit-tested in isolation.
  • napi ExecuteOptions exposes rowLimit + queryTimeoutSecs, threaded onto the spec; scalars are read before options is consumed by the query-tags merge.

Layering

Logic lives in the kernel (StatementSpec → prepare_for_dispatch); napi is a thin pass-through. The NodeJS SEA adapter maps its public ExecuteStatementOptions.maxRows / queryTimeout onto these napi fields in a separate driver PR.

Downstream fixes / reviewer note

  • NodeJS consumption is intentionally split downstream: databricks-sql-nodejs#403 wires queryTimeout to queryTimeoutSecs, and databricks-sql-nodejs#408 wires rowLimit to the kernel row_limit field.
  • Any review concern that the NodeJS SEA layer still lacks these public options is covered by those later PRs; this PR only exposes the kernel/napi primitives.
  • 2026-06-01 kernel reviewer note: Reviewer note: this PR already includes the inline-result row-overrun bug fix (fix(reader): clamp inline result to manifest.total_row_count) alongside the public row_limit / query_timeout_secs surface, so reviewers should not request a separate follow-up for inline Arrow over-fetch within this stack.
  • 2026-06-01 kernel reviewer note: Reviewer note: NodeJS exposure of rowLimit lands later in databricks-sql-nodejs#408; this kernel PR only makes the kernel/napi knobs available.

Validation

  • cargo fmt --all + cargo clippy --lib clean.
  • New unit tests: StatementSpec setters/defaults; resolve_wait_timeout (async-submit, sync+timeout→CANCEL, sync default→omit); the unchanged query-tags merge still passes (16 napi tests green).
  • The SEA server clamps wait_timeout at 50s; the kernel forwards the requested value verbatim and lets the server clamp.

This pull request and its description were written by Isaac.

… on StatementSpec

Closes the SEA↔Thrift parity rows 2.15 (row_limit) and 2.17 (server
statement timeout) from the cross-driver feature matrix. Both are
exercised by Python `use_sea` (row_limit=, wait_timeout=) but were not
reachable through the kernel's public StatementSpec, so NodeJS SEA and
Python use_kernel could not offer them.

- StatementSpec gains `row_limit: Option<i64>` and
  `query_timeout_secs: Option<u32>` with fluent setters. The SEA wire
  request already carried `row_limit` / `wait_timeout` / `on_wait_timeout`
  (types::sea::ExecuteParams); this only surfaces them on the public spec
  and threads them through `prepare_for_dispatch` — no new wire surface.

- Server statement timeout maps to SEA `wait_timeout` with
  `on_wait_timeout = CANCEL` so the statement is cancelled on elapse
  (JDBC setQueryTimeout / Python use_sea wait_timeout semantics), distinct
  from the connection-level transport `overall_timeout`. The wait-timeout
  precedence (async-submit "0s" respected verbatim vs sync-execute honoring
  the spec timeout vs server default) is extracted into the pure
  `resolve_wait_timeout` helper and unit-tested.

- napi `ExecuteOptions` exposes `rowLimit` + `queryTimeoutSecs`, threaded
  onto the spec; the scalars are read before `options` is consumed by the
  query-tags merge.

Validation: cargo fmt + clippy clean; new unit tests cover the spec
setters, the wait-timeout precedence (3 cases), and the unchanged
query-tags merge. The SEA server clamps wait_timeout at 50s; the kernel
forwards the requested value verbatim.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
With a row_limit applied, the SEA server returns one extra look-ahead
Arrow row beyond the logical result size and marks the manifest
`truncated = true` with `total_row_count = N` (the requested limit). The
inline reader decoded the raw Arrow stream verbatim, so `row_limit = N`
surfaced N+1 rows — verified live (limit 10 → 11 rows, ids 0..10; limit 5
→ 6) and against the SEA response manifest, which reports `total_row_count
= 10, truncated = true` for a limit of 10.

The manifest count — not the raw Arrow row count — is the authoritative
result size. `InlineArrowProvider::new` now takes the manifest's
`total_row_count` and clamps the decoded batches to it (slicing the batch
that crosses the boundary), mirroring the Python SEA connector, which
bounds its `ArrowQueue` by `total_row_count`. This makes `row_limit`
return exactly N rows — parity with Python use_sea and Thrift.

`None` (count absent) leaves batches unclamped; an above-actual count is a
no-op. The clamp arithmetic is a pure, unit-tested helper.

Verified live: row_limit 10 → 10 rows, 5 → 5 rows; non-limited queries
unchanged. New unit tests cover None-passthrough, cross-batch slicing,
above-actual no-op, and the N+1 look-ahead clamp.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #101, which is now the main-based kernel SEA parity mega PR for agent review. The branch is preserved and this can be reopened if we decide to return to smaller stacked reviews.

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