Repository navigation
Add a Trino SQL client and dialect - #10632
Open
effect-bot wants to merge 4 commits into
Open
effect-bot wants to merge 4 commits into
effect-bot wants to merge 4 commits into
Conversation
Scripted-coordinator unit tests and container integration tests that pin the Trino driver contract: lossless bigint decoding, EXECUTE IMMEDIATE literal parameters, session headers, transaction ids, cancellation, POST retry limited to 429/503, SqlError classification and the trino dialect. The driver itself is not implemented yet, so these tests fail.
TrinoClient speaks Trino's HTTP client protocol through HttpClient: statements with parameters run as EXECUTE IMMEDIATE with literal parameters, rows are decoded losslessly from the raw response text, session and transaction headers are tracked, interrupted queries are cancelled, and only safe requests are retried. Adds "trino" to Statement.Dialect and a Trino path in Migrator that runs without a transaction and records created_at explicitly.
🦋 Changeset detectedLatest commit: d197c57 The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 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.
|
… and release retried responses - reserved and transaction connections copy the client session - a failed COMMIT rolls back the transaction through onCommitFailure - __proto__ stays an own property in rows, maps and named rows - each request attempt runs in its own scope, so discarded responses are released - Retry-After accepts the HTTP-date form
… and extend SqlClient.Base Read the first page and later pages through one paginate loop, render parameter and array literals in one place, and derive the page-read retry policy from the submit policy. TrinoClient now extends SqlClient.Base like the other drivers, so providing a generic SqlClient no longer removes the TrinoClient requirement. Adds the type test the other drivers have.
This branch has not been 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
@effect/sql-trino, a SQL client and migrator for Trino, and atrinodialect ineffect/sql.Closes #10621
Closes EFF-3786
How it works
The client speaks Trino's HTTP client protocol through the
HttpClientin the environment, so it has no driver dependency and runs anywhereHttpClientdoes. A statement goes out asPOST /v1/statement, and its rows are read by followingnextUriuntil the query finishes. Streams fetch pages on demand.EXECUTE IMMEDIATE '<sql with ?>' USING <literals>. This needs Trino 418 or later. Supported values are strings, numbers, bigints, booleans,null,Date,Uint8Arrayand arrays of these. Any other value fails with aSqlErrorbefore anything is sent.bigintas bare JSON numbers, whichJSON.parserounds above 2^53. The client parses the response text itself, then decodes each column by its type:bigintbecomesbigint,timestamp(read as UTC) andtimestamp with time zonebecomeDate,varbinarybecomesUint8Array,jsonis parsed, anddecimalanddatestay strings. Arrays, maps and rows are decoded recursively.USEorSET SESSIONstays with it.START TRANSACTIONis sent withX-Trino-Transaction-Id: NONE, and the returned id is used untilCOMMITorROLLBACK. IfCOMMITfails while the server still holds the transaction, the client sendsROLLBACKwith the same id. Trino has no savepoints, so a nestedwithTransactionfails and the outer transaction rolls back.Retry-Afterin seconds or as an HTTP date) and 503, because after any other failure the statement may already be running. Page reads are idempotent, so they also retry on 502, 504 and network errors.retryTimeout(default 2 minutes) bounds both. Each attempt runs in its own request scope, so a response that is discarded before a retry is released straight away.DELETEto the currentnextUri.SqlErrorreasons from the Trino error name (SYNTAX_ERROR,PERMISSION_DENIED,EXCEEDED_TIME_LIMIT) and from HTTP 401 and 403.Changes in
effectStatement.Dialectgains"trino", andonDialect/onDialectOrElsegain atrinobranch.onDialectrequires every branch, so existing callers have to add one. The changeset says so.Migratorcreatescreated_at timestampon Trino and writes it explicitly as a UTC literal, because Trino has no column defaults. Trino migrations also run without a transaction, as ClickHouse migrations already do, because connectors such as memory reject writes inside one.Review guide
packages/sql/trino/test/TrinoCoordinator.ts, plus integration tests againsttrinodb/trino:484.packages/sql/trino/src/TrinoClient.ts.COMMIT,__proto__as a column name or map key, releasing retried responses, and HTTP-dateRetry-After.TrinoClientnow extendsSqlClient.Baselike the other drivers, so providing a genericSqlClientdoes not remove aTrinoClientrequirement, and the package has the type test the other drivers have.Validation
pnpm lint-fix,pnpm checkandpnpm jsdocs --checkare clean.pnpm test --run packages/sql/trino packages/effect/test/sql packages/effect/test/Migrator.test.ts packages/sql/clickhouse/test: 132 passed.EFFECT_INTEGRATION_TESTS=1 pnpm test --runon the two Trino integration files: 4 passed againsttrinodb/trino:484.pnpm test-typesonpackages/effect/typetest/sql/Statement.tst.tsandpackages/sql/trino/typetest/TrinoClient.tst.ts: passed.pnpm buildandpnpm pack --dry-runinpackages/sql/trino.