Skip to main content

Module driver

Module driver 

Source
Expand description

The async statement driver: pump the pure StatementMachine against the live franken-snowflake-http transport, cancel-correctly.

This is the thin async glue over the pure lifecycle logic. All decisions (status routing, the poll loop, partition assembly) live in crate::lifecycle; this module only performs the network steps the machine asks for and, crucially, fires the SQL API cancel endpoint when the ambient Cx is cancelled after a statement handle exists — so no Snowflake statement is orphaned (the obligation/bracket contract from docs/asupersync_leverage.md).

The cancel path delegates to the transport’s own cancel_after_local_cancel, which masks local cancellation for the bounded cleanup request and single-sources the cancel-policy table. Either way the local outcome is Cancelled.

Structs§

DriverStats
Observed effort for one driven statement, for budget_consumed reporting.
MultiStatementResult
The results of a multi-statement request (reality-check bead L1).
StatementHooks
Optional per-run hooks: a streaming row sink and a progress observer.

Enums§

DriverEvent
What happened during a statement run, for progress reporting (reality-check bead E5). Carries no SQL text and no credential.

Traits§

AuthProvider
Supplies the bearer for each SQL API request and decides what to do when the API answers 401.
DriverObserver
Receives DriverEvents while a statement runs.
RowSink
Receives a statement’s rows in partition order while it streams (reality-check bead E5).
StatementTransport
The transport operations the driver needs. SnowflakeHttpClient is the production implementation; tests inject a scripted fake so the driver’s error and cancellation paths are provable without a socket or an account.

Functions§

run_multi_statement_hooked
Run a request whose MULTI_STATEMENT_COUNT is above one (reality-check bead L1): the parent statement, then each statement fetched by the handle the parent lists (GET /api/v2/statements/{handle}), in statement order. Each statement assembles like a single one (polls, partitions, the plan’s row cap). A failing statement fails the request with 422 before any result is fetched. The observer sees every step.
run_statement
Submit a statement and drive it to completion: submit -> poll/await -> partition fetch -> assemble, firing the remote cancel endpoint if the ambient Cx is cancelled mid-flight.
run_statement_hooked
run_statement_with_auth with optional StatementHooks.
run_statement_streaming
run_statement_with_auth, handing rows to sink as each fetch window completes instead of assembling them, so peak memory is one window of partitions. The returned CompletedStatement keeps the metadata; its rows are empty because every row went to the sink.
run_statement_with_auth
run_statement_with_stats with a refreshing AuthProvider: the bearer is re-derived before every request and a 401 triggers one re-sign + retry of the same step when the provider can refresh.
run_statement_with_stats
run_statement plus the poll/partition counts it consumed.

Type Aliases§

StatementOutcome
The driver outcome: a fully-assembled CompletedStatement or one of the four SnowflakeOutcome terminal states.