Skip to content

Add a Trino SQL client and dialect - #10632

Open
effect-bot wants to merge 4 commits into
mainfrom
agent/nelson-effect-bot/7c4f6b15d881
Open

effect-bot wants to merge 4 commits into
mainfrom
agent/nelson-effect-bot/7c4f6b15d881

Conversation

@effect-bot

@effect-bot effect-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Adds @effect/sql-trino, a SQL client and migrator for Trino, and a trino dialect in effect/sql.

Closes #10621
Closes EFF-3786

How it works

The client speaks Trino's HTTP client protocol through the HttpClient in the environment, so it has no driver dependency and runs anywhere HttpClient does. A statement goes out as POST /v1/statement, and its rows are read by following nextUri until the query finishes. Streams fetch pages on demand.

  • Parameters. Trino has no protocol-level parameters, so a statement with parameters is sent as EXECUTE IMMEDIATE '<sql with ?>' USING <literals>. This needs Trino 418 or later. Supported values are strings, numbers, bigints, booleans, null, Date, Uint8Array and arrays of these. Any other value fails with a SqlError before anything is sent.
  • Decoding. Trino sends bigint as bare JSON numbers, which JSON.parse rounds above 2^53. The client parses the response text itself, then decodes each column by its type: bigint becomes bigint, timestamp (read as UTC) and timestamp with time zone become Date, varbinary becomes Uint8Array, json is parsed, and decimal and date stay strings. Arrays, maps and rows are decoded recursively.
  • Session. Catalog, schema, session property and prepared-statement changes returned by the server apply to later statements on the same session. Statements outside a transaction share the client's session. A reserved connection or a transaction starts from a copy, so its USE or SET SESSION stays with it.
  • Transactions. START TRANSACTION is sent with X-Trino-Transaction-Id: NONE, and the returned id is used until COMMIT or ROLLBACK. If COMMIT fails while the server still holds the transaction, the client sends ROLLBACK with the same id. Trino has no savepoints, so a nested withTransaction fails and the outer transaction rolls back.
  • Retries. The submit request is retried only on 429 (honouring Retry-After in 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.
  • Cancellation. Interrupting a statement, or ending a stream early, sends DELETE to the current nextUri.
  • Errors. Errors map to SqlError reasons from the Trino error name (SYNTAX_ERROR, PERMISSION_DENIED, EXCEEDED_TIME_LIMIT) and from HTTP 401 and 403.

Changes in effect

  • Statement.Dialect gains "trino", and onDialect / onDialectOrElse gain a trino branch. onDialect requires every branch, so existing callers have to add one. The changeset says so.
  • Migrator creates created_at timestamp on 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

  • Commit 1 has the tests: unit tests against a scripted coordinator in packages/sql/trino/test/TrinoCoordinator.ts, plus integration tests against trinodb/trino:484.
  • Commit 2 has the implementation, mostly packages/sql/trino/src/TrinoClient.ts.
  • Commit 3 fixes review findings, each with a unit regression: session isolation, rollback after a failed COMMIT, __proto__ as a column name or map key, releasing retried responses, and HTTP-date Retry-After.
  • Commit 4 is a simplification pass with no runtime behaviour change. TrinoClient now extends SqlClient.Base like the other drivers, so providing a generic SqlClient does not remove a TrinoClient requirement, and the package has the type test the other drivers have.

Validation

  • pnpm lint-fix, pnpm check and pnpm jsdocs --check are 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 --run on the two Trino integration files: 4 passed against trinodb/trino:484.
  • pnpm test-types on packages/effect/typetest/sql/Statement.tst.ts and packages/sql/trino/typetest/TrinoClient.tst.ts: passed.
  • pnpm build and pnpm pack --dry-run in packages/sql/trino.

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-bot

changeset-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d197c57

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
effect Patch
@effect/sql-trino Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-cloudflare Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

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

@effect-janitor effect-janitor Bot added the 4.0 label Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.88 KB 39.88 KB 0.00 KB (0.00%)
basic.ts 7.31 KB 7.31 KB 0.00 KB (0.00%)
batching.ts 11.21 KB 11.21 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.73 KB 11.73 KB 0.00 KB (0.00%)
config.ts 23.09 KB 23.09 KB 0.00 KB (0.00%)
differ.ts 22.20 KB 22.20 KB 0.00 KB (0.00%)
http-client.ts 27.45 KB 27.45 KB 0.00 KB (0.00%)
http-router.ts 37.55 KB 37.55 KB 0.00 KB (0.00%)
logger.ts 12.19 KB 12.19 KB 0.00 KB (0.00%)
metric.ts 9.65 KB 9.65 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.21 KB 16.21 KB 0.00 KB (0.00%)
queue.ts 13.09 KB 13.09 KB 0.00 KB (0.00%)
schedule.ts 11.99 KB 11.99 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.29 KB 14.29 KB 0.00 KB (0.00%)
schema-binary.ts 42.45 KB 42.45 KB 0.00 KB (0.00%)
schema-class.ts 21.96 KB 21.96 KB 0.00 KB (0.00%)
schema-codegen.ts 30.70 KB 30.70 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.56 KB 30.56 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.26 KB 28.26 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.54 KB 15.54 KB 0.00 KB (0.00%)
schema-string.ts 12.50 KB 12.50 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.43 KB 16.43 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.41 KB 39.41 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.11 KB 21.11 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.28 KB 21.28 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.37 KB 21.37 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.42 KB 26.42 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
stm.ts 14.40 KB 14.40 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)

… 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL driver for Trino (@effect/sql-trino), and a trino SQL dialect

1 participant