You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a SQL Statement Execution fake to the testserver (#5432)
## Summary
Adds `libs/testserver/testsql`, a pluggable fake of the SQL Statement
Execution API, so tests can drive `/api/2.0/sql/statements` natively
instead of hand-building `StatementResponse` stubs.
Tests register matchers via `Server.HandleSQL` (exact) /
`Server.HandleSQLPattern` (regex), each mapping a statement to a
declarative result — columns, rows, an optional error, a poll count, and
a chunk count. The testserver models the full lifecycle over the real
HTTP endpoints: submit (honoring `wait_timeout`), poll, chunk
pagination, and cancel. A matcher runs once per submission, so a matcher
that closes over a map can model stateful resources (create then read
back).
The lifecycle routes are registered in `AddDefaultHandlers` as
overridable defaults: a raw `Server.Handle` for the same pattern
registered before `AddDefaultHandlers` wins, as do `test.toml` stubs in
acceptance — preserving an escape hatch for responses the fake doesn't
model (malformed bodies, transport errors, custom status codes).
The `libs/sqlexec` HTTP tests are migrated onto the fake, replacing
per-test `StatementResponse` construction with one-line matchers.
## Cross-check against the real API
Behaviors were verified against a live SQL warehouse, which drove three
refinements:
- A no-row statement (0-row `SELECT` or no-result-set DDL) reports
`total_chunk_count: 0` with an empty result; the fake now matches
(previously it always emitted one empty chunk).
- `status.sql_state` is populated on failures (e.g. `42P01`); added an
assertion to the failed-statement integration test so the typed
`StatementError.SQLState` contract is covered.
- Documented on `Result.Rows` that SQL `NULL` and empty string are
indistinguishable there: the wire format encodes `NULL` as JSON `null`,
but the SDK models cells as `[][]string`, so `null` decodes to `""`.
Recovering the distinction would need a null-aware cell type or the
`ARROW_STREAM` format; no caller needs it today.
## Test plan
- `sqlexec` integration suite passes live (`TestSQLExec*`, incl. the new
`SQLState` assertion).
This pull request and its description were written by Isaac.
0 commit comments