Repository navigation
Add ClickhouseClient.queryStream for streaming results in any ClickHouse format - #8544
Open
arrudaricardo wants to merge 2 commits into
Open
arrudaricardo wants to merge 2 commits into
arrudaricardo wants to merge 2 commits into
Conversation
…e context Groundwork for streaming queries, with no behaviour change: - Extract `killQuery` and `toQueryParams`, and move `insertQuery` onto the connection so every request path cancels the same way. - Read `ClientMethod`, `QueryId`, and `ClickhouseSettings` with `yield*` instead of `fiber.getRef` / `Fiber.getCurrent()`. - Describe those references as context references in their JSDoc. - Reset the client mock between tests and cover that a custom query id and settings apply only to the query they are set on.
…use format
`queryStream(sql`...`, { format })` streams a statement's results in any
streamable ClickHouse format. JSON formats emit decoded rows with
`transformResultNames` applied (including the `row`, `totals`, `min`, and
`max` payloads of `JSONEachRowWithProgress` events); raw formats go through
`exec` and emit the response body untouched as `Uint8Array` chunks.
- Failures are classified like regular queries. `JSONEachRowWithProgress`
enables `http_write_exception_in_output_format` unless it is set in the
client config or per request, so a failure after streaming has started
arrives as a final `{exception}` event instead of a trailer that is lost
when a slow consumer lets the connection reset.
- Unless the response is read to the end or the server rejected the request,
closing the stream aborts the request and kills the query. This covers
interruption, early termination such as `Stream.take`, and downstream
failures; closing the socket alone does not stop a query that is still
computing.
- Raw formats strip trailing semicolons and start the appended `FORMAT`
clause on a new line so a trailing `--` comment cannot swallow it.
🦋 Changeset detectedLatest commit: eeb0262 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
arrudaricardo
marked this pull request as ready for review
September 26, 2026 00:52
This branch is waiting to be 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.
Adds
ClickhouseClient.queryStream, which streams asqlstatement's results in any streamable ClickHouse format.transformResultNamesapplied. WithJSONEachRowWithProgress, rows arrive alongside progress events, and therow,totals,min, andmaxpayloads are transformed.execand emit the response body untouched asUint8Arraychunks.ResultSet.stream()splits on newline bytes, which would corrupt Parquet.sqlstatement, so interpolated values,client.param, andtransformQueryNameswork the same as for other queries.Reviewing
Please review commit by commit:
killQueryandtoQueryParams, movesinsertQueryonto the connection, and readsClientMethod,QueryIdandClickhouseSettingswithyield*instead offiber.getRef. Existing tests pass unchanged; one test is added for the query id and settings path.Validation
packages/sql/clickhouseunit tests (29),tsc -b, oxlint, dprint.KILL QUERYsent on interrupt,Stream.take, and consumer failure, and not sent when fully read (checked insystem.query_log)--comment casetotals/min/maxtransformseffect-jsdocs --checkreports only existing errors in files this PR doesn't touch (ai/DecisionModel.ts,encoding/Base64*.ts).