| Title: | 'DBI' Backend for 'Trino' |
|---|---|
| Description: | A 'DBI' compliant backend for 'Trino' <https://trino.io>, the distributed SQL query engine (successor of 'PrestoSQL'). Connects to a 'Trino' cluster over its HTTP REST API, executes queries with automatic pagination, maps 'Trino' types to R types, and integrates with 'dplyr' through 'dbplyr' SQL dialects. Supports basic, JSON Web Token (JWT) bearer and OAuth2 client credentials authentication, as well as custom certificate authorities. |
| Authors: | Luis A Casas Ballestas [aut, cre, cph] |
| Maintainer: | Luis A Casas Ballestas <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-15 17:18:39 UTC |
| Source: | https://github.com/cran/RTrino |
Builds one INSERT INTO ... VALUES (...) statement per batch of rows,
with values quoted as literals by DBI::sqlAppendTable() (which calls
dbQuoteIdentifier() and dbQuoteLiteral() for Trino) — there is no
parameter binding to fall back on.
## S4 method for signature 'TrinoConnection' dbAppendTable(conn, name, value, ..., row.names = NULL)## S4 method for signature 'TrinoConnection' dbAppendTable(conn, name, value, ..., row.names = NULL)
conn |
A TrinoConnection object. |
name |
Table name, in any form |
value |
A data frame with the rows to insert. |
... |
Takes |
row.names |
Unused: RTrino never writes row names as a column. |
The number of rows inserted.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbCreateTable(con, "sales", c(id = "integer", label = "varchar")) DBI::dbAppendTable(con, "sales", data.frame(id = 1:3, label = letters[1:3])) DBI::dbGetQuery(con, "SELECT * FROM sales ORDER BY id") DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbCreateTable(con, "sales", c(id = "integer", label = "varchar")) DBI::dbAppendTable(con, "sales", data.frame(id = 1:3, label = letters[1:3])) DBI::dbGetQuery(con, "SELECT * FROM sales ORDER BY id") DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)
Every statement runs inside Trino's engine-level transaction mechanism:
dbBegin() sends START TRANSACTION and keeps the transaction id Trino
answers with, which is then carried on every later request until
dbCommit() or dbRollback() sends COMMIT or ROLLBACK and clears
it.
## S4 method for signature 'TrinoConnection' dbBegin(conn, ...) ## S4 method for signature 'TrinoConnection' dbCommit(conn, ...) ## S4 method for signature 'TrinoConnection' dbRollback(conn, ...)## S4 method for signature 'TrinoConnection' dbBegin(conn, ...) ## S4 method for signature 'TrinoConnection' dbCommit(conn, ...) ## S4 method for signature 'TrinoConnection' dbRollback(conn, ...)
conn |
A TrinoConnection object. |
... |
Unused, for compatibility with the generic. |
Whether a ROLLBACK actually undoes a write depends on the connector
behind the active catalog, not on RTrino: Iceberg and Delta Lake tables
support it, most others (including Hive, strictly) only partially, and
Trino's own synthetic catalogs (memory, tpch, ...) not at all.
dbBegin() warns when the active catalog is one of the latter.
TRUE, invisibly.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") # tpch holds no real storage, so dbBegin() warns that a ROLLBACK would # undo nothing. On an Iceberg or Delta Lake catalog it would not. DBI::dbBegin(con) DBI::dbGetQuery(con, "SELECT count(*) AS n FROM nation") DBI::dbCommit(con) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") # tpch holds no real storage, so dbBegin() warns that a ROLLBACK would # undo nothing. On an Iceberg or Delta Lake catalog it would not. DBI::dbBegin(con) DBI::dbGetQuery(con, "SELECT count(*) AS n FROM nation") DBI::dbCommit(con) DBI::dbDisconnect(con)
Trino's client protocol has no parameter binding of its own, so rather than
ignoring the values, dbBind() fails.
## S4 method for signature 'TrinoResult' dbBind(res, params, ...)## S4 method for signature 'TrinoResult' dbBind(res, params, ...)
res |
A TrinoResult object. |
params |
Unused. |
... |
Unused. |
Never returns.
Frees the buffered rows and marks the cursor cleared. If the query is still
running on the server, a DELETE is sent to its nextUri so the
coordinator stops working on it instead of letting it run to completion for
nobody.
## S4 method for signature 'TrinoResult' dbClearResult(res, ...)## S4 method for signature 'TrinoResult' dbClearResult(res, ...)
res |
A TrinoResult object. |
... |
Unused, for compatibility with the generic. |
TRUE, invisibly.
Creates a TrinoConnection. Trino's REST API is stateless, so no
session is opened on the server; the connection object holds the coordinator
address and the per-request settings. To fail early on a wrong address or
bad credentials, dbConnect() probes GET /v1/info before returning.
## S4 method for signature 'TrinoDriver' dbConnect( drv, host = "http://localhost", port = 8080L, user = trino_default_user(), catalog = NULL, schema = NULL, source = "RTrino", session.timezone = "UTC", bigint = c("integer64", "numeric", "character"), auth = NULL, ssl_options = trino_ssl(), extra.headers = list(), timeout = 60, query_max_run_time = NULL, allow_http_auth = FALSE, ... )## S4 method for signature 'TrinoDriver' dbConnect( drv, host = "http://localhost", port = 8080L, user = trino_default_user(), catalog = NULL, schema = NULL, source = "RTrino", session.timezone = "UTC", bigint = c("integer64", "numeric", "character"), auth = NULL, ssl_options = trino_ssl(), extra.headers = list(), timeout = 60, query_max_run_time = NULL, allow_http_auth = FALSE, ... )
drv |
A TrinoDriver object, from |
host |
Coordinator URL. A missing scheme defaults to |
port |
Coordinator port, a whole number between 1 and 65535. |
user |
Trino user name, sent as |
catalog |
Trino catalog. Required. |
schema |
Trino schema. Required. |
source |
Value of the |
session.timezone |
Session time zone, used when reading |
bigint |
How to return |
auth |
An authentication closure from |
ssl_options |
TLS options from |
extra.headers |
Named list of extra HTTP headers added to every
request, each a single string. Useful for Trino session properties set
through |
timeout |
Seconds allowed for each HTTP request to the coordinator,
not for the whole query; |
query_max_run_time |
Longest a query may run on the cluster before
Trino stops it, as a Trino duration such as |
allow_http_auth |
Set to |
... |
Unused, for compatibility with the generic. |
A TrinoConnection object.
A query is a series of HTTP requests, so two limits apply. timeout bounds
each request: a coordinator or network that stops answering fails with an
error instead of blocking the R session. query_max_run_time bounds the
query as a whole on the server: past it, Trino stops the query and RTrino
raises a trino_query_error whose error_name is "EXCEEDED_TIME_LIMIT".
In a Shiny app, where a blocked session blocks its user, set both.
# The examples in this package run against the coordinator that # RTRINO_TEST_URL points at, such as "http://localhost:8080" for # `docker run -p 8080:8080 trinodb/trino`. It has no authentication. con <- DBI::dbConnect( RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny" ) con DBI::dbDisconnect(con) # LDAP over TLS, with limits for use in a Shiny app ## Not run: con <- DBI::dbConnect( RTrino::Trino(), host = "https://trino.example.com", port = 443, user = Sys.getenv("TRINO_USER"), catalog = "hive", schema = "analytics", auth = trino_auth_basic(Sys.getenv("TRINO_USER"), Sys.getenv("TRINO_PASSWORD")), timeout = 30, query_max_run_time = "5m" ) DBI::dbDisconnect(con) ## End(Not run)# The examples in this package run against the coordinator that # RTRINO_TEST_URL points at, such as "http://localhost:8080" for # `docker run -p 8080:8080 trinodb/trino`. It has no authentication. con <- DBI::dbConnect( RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny" ) con DBI::dbDisconnect(con) # LDAP over TLS, with limits for use in a Shiny app ## Not run: con <- DBI::dbConnect( RTrino::Trino(), host = "https://trino.example.com", port = 443, user = Sys.getenv("TRINO_USER"), catalog = "hive", schema = "analytics", auth = trino_auth_basic(Sys.getenv("TRINO_USER"), Sys.getenv("TRINO_PASSWORD")), timeout = 30, query_max_run_time = "5m" ) DBI::dbDisconnect(con) ## End(Not run)
Trino has no temporary tables, so temporary = TRUE is an error rather
than being silently ignored.
## S4 method for signature 'TrinoConnection' dbCreateTable(conn, name, fields, ..., row.names = NULL, temporary = FALSE)## S4 method for signature 'TrinoConnection' dbCreateTable(conn, name, fields, ..., row.names = NULL, temporary = FALSE)
conn |
A TrinoConnection object. |
name |
Table name, in any form |
fields |
Either a named character vector of Trino types, one per
column, or a data frame whose columns' R types are mapped to Trino
types with |
... |
Unused, for compatibility with the generic. |
row.names |
Unused: RTrino never writes row names as a column. |
temporary |
Must be |
TRUE, invisibly.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbCreateTable(con, "sales", c(id = "bigint", label = "varchar")) DBI::dbListFields(con, "sales") DBI::dbRemoveTable(con, "sales") # The column types can also follow a data frame's DBI::dbCreateTable(con, "sales", data.frame(id = 1L, label = "a")) DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbCreateTable(con, "sales", c(id = "bigint", label = "varchar")) DBI::dbListFields(con, "sales") DBI::dbRemoveTable(con, "sales") # The column types can also follow a data frame's DBI::dbCreateTable(con, "sales", data.frame(id = 1L, label = "a")) DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)
The inverse of trino_type_to_r(): used by dbCreateTable() to pick a
column type when the caller does not give one explicitly.
## S4 method for signature 'TrinoConnection' dbDataType(dbObj, obj, ...)## S4 method for signature 'TrinoConnection' dbDataType(dbObj, obj, ...)
dbObj |
A TrinoConnection object. |
obj |
An R vector, or a data frame (one call per column). |
... |
Unused, for compatibility with the generic. |
A string naming a Trino type.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbDataType(con, 1L) DBI::dbDataType(con, Sys.Date()) DBI::dbDataType(con, data.frame(id = 1L, label = "a")) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbDataType(con, 1L) DBI::dbDataType(con, Sys.Date()) DBI::dbDataType(con, data.frame(id = 1L, label = "a")) DBI::dbDisconnect(con)
Marks the connection as closed. Trino's REST API is stateless, so nothing is
sent to the server; any later use of conn raises an error.
## S4 method for signature 'TrinoConnection' dbDisconnect(conn, ...)## S4 method for signature 'TrinoConnection' dbDisconnect(conn, ...)
conn |
A TrinoConnection object. |
... |
Unused, for compatibility with the generic. |
TRUE, invisibly.
Runs the statement to completion and reports how many rows Trino says it
changed: the count of an INSERT, an UPDATE, a DELETE, a MERGE or a
CREATE TABLE ... AS SELECT, and 0 for a statement that changes no rows,
such as CREATE TABLE or DROP TABLE.
## S4 method for signature 'TrinoConnection,character' dbExecute(conn, statement, ...)## S4 method for signature 'TrinoConnection,character' dbExecute(conn, statement, ...)
conn |
A TrinoConnection object. |
statement |
A single SQL statement. |
... |
Unused, for compatibility with the generic. |
The number of affected rows, invisibly: a double, or NA for a data
change whose count Trino did not report.
Asks information_schema for a count, so the answer costs the same whatever
the schema holds. Trino folds every identifier to lower case, so the name is
matched the same way: "SALES" exists if sales does, as
SELECT * FROM SALES would find it.
## S4 method for signature 'TrinoConnection,character' dbExistsTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbExistsTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbExistsTable(conn, name, ...)## S4 method for signature 'TrinoConnection,character' dbExistsTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbExistsTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbExistsTable(conn, name, ...)
conn |
A TrinoConnection object. |
name |
Table name, required. A string: |
... |
Unused, for compatibility with the generic. |
A logical scalar. A name in a catalog or schema that does not exist
is simply FALSE, not an error.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbExistsTable(con, "nation") DBI::dbExistsTable(con, "tpch.sf1.nation") DBI::dbExistsTable(con, DBI::Id(catalog = "tpch", schema = "sf1", table = "nation")) DBI::dbExistsTable(con, "no_such_table") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbExistsTable(con, "nation") DBI::dbExistsTable(con, "tpch.sf1.nation") DBI::dbExistsTable(con, DBI::Id(catalog = "tpch", schema = "sf1", table = "nation")) DBI::dbExistsTable(con, "no_such_table") DBI::dbDisconnect(con)
Pulls rows from the cursor, following Trino's nextUri chain as needed, and
converts each column to its R type according to the column's declared Trino
type and the connection's bigint setting.
## S4 method for signature 'TrinoResult' dbFetch(res, n = -1, ...)## S4 method for signature 'TrinoResult' dbFetch(res, n = -1, ...)
res |
A TrinoResult object. |
n |
Number of rows to fetch. |
... |
Unused, for compatibility with the generic. |
A tibble. Once the result is exhausted, a zero-row tibble with the right columns and types.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") res <- DBI::dbSendQuery(con, "SELECT * FROM orders") while (!DBI::dbHasCompleted(res)) { chunk <- DBI::dbFetch(res, n = 4000) # process chunk; here, just count its rows cat(nrow(chunk), "rows\n") } DBI::dbClearResult(res) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") res <- DBI::dbSendQuery(con, "SELECT * FROM orders") while (!DBI::dbHasCompleted(res)) { chunk <- DBI::dbFetch(res, n = 4000) # process chunk; here, just count its rows cat(nrow(chunk), "rows\n") } DBI::dbClearResult(res) DBI::dbDisconnect(con)
Reports the connection's settings plus the coordinator's version, read from
/v1/info. If that endpoint cannot be reached, db.version is NA rather
than an error, so the rest of the metadata stays available.
## S4 method for signature 'TrinoConnection' dbGetInfo(dbObj, ...)## S4 method for signature 'TrinoConnection' dbGetInfo(dbObj, ...)
dbObj |
A TrinoConnection object. |
... |
Unused, for compatibility with the generic. |
A list with db.version, host, port, user, catalog and
schema.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbGetInfo(con) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbGetInfo(con) DBI::dbDisconnect(con)
Submits the statement, fetches every row and clears the result, even if fetching fails.
## S4 method for signature 'TrinoConnection,character' dbGetQuery(conn, statement, n = -1, ...)## S4 method for signature 'TrinoConnection,character' dbGetQuery(conn, statement, n = -1, ...)
conn |
A TrinoConnection object. |
statement |
A single SQL statement. |
n |
Number of rows to return; |
... |
Unused, for compatibility with the generic. |
A tibble.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbGetQuery(con, "SELECT * FROM nation LIMIT 5") DBI::dbGetQuery(con, "SELECT * FROM nation", n = 3) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbGetQuery(con, "SELECT * FROM nation LIMIT 5") DBI::dbGetQuery(con, "SELECT * FROM nation", n = 3) DBI::dbDisconnect(con)
TRUE once Trino has stopped handing out pages and the rows already
pulled have been handed to the caller. A result that has finished on the
server but still holds buffered rows is not complete, so a
while (!dbHasCompleted(res)) loop over dbFetch() sees every row.
## S4 method for signature 'TrinoResult' dbHasCompleted(res, ...)## S4 method for signature 'TrinoResult' dbHasCompleted(res, ...)
res |
A TrinoResult object. |
... |
Unused, for compatibility with the generic. |
A logical scalar.
A connection is valid until dbDisconnect() is called. A result is valid
until it is cleared by dbClearResult() - a result whose rows have all been
fetched is still valid, so that dbColumnInfo() and friends keep working.
## S4 method for signature 'TrinoConnection' dbIsValid(dbObj, ...) ## S4 method for signature 'TrinoResult' dbIsValid(dbObj, ...)## S4 method for signature 'TrinoConnection' dbIsValid(dbObj, ...) ## S4 method for signature 'TrinoResult' dbIsValid(dbObj, ...)
dbObj |
A TrinoConnection or TrinoResult object. |
... |
Unused, for compatibility with the generic. |
A logical scalar.
List a table's columns
## S4 method for signature 'TrinoConnection,character' dbListFields(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbListFields(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbListFields(conn, name, ...)## S4 method for signature 'TrinoConnection,character' dbListFields(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbListFields(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbListFields(conn, name, ...)
conn |
A TrinoConnection object. |
name |
Table name, required, in any form
dbExistsTable() accepts:
a string with one to three dot-separated parts, a |
... |
Unused, for compatibility with the generic. |
A character vector of column names.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbListFields(con, "nation") DBI::dbListFields(con, DBI::Id(schema = "sf1", table = "region")) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbListFields(con, "nation") DBI::dbListFields(con, DBI::Id(schema = "sf1", table = "region")) DBI::dbDisconnect(con)
List the tables in the connection's schema
## S4 method for signature 'TrinoConnection' dbListTables(conn, ...)## S4 method for signature 'TrinoConnection' dbListTables(conn, ...)
conn |
A TrinoConnection object. |
... |
Unused, for compatibility with the generic. |
A character vector of table names.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbListTables(con) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbListTables(con) DBI::dbDisconnect(con)
Trino follows the SQL standard: identifiers are wrapped in double quotes
with embedded double quotes doubled, and string literals are wrapped in
single quotes with embedded single quotes doubled. A value that is already
DBI::SQL() is returned unchanged rather than quoted a second time.
## S4 method for signature 'TrinoConnection,character' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'TrinoConnection,SQL' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'TrinoConnection,character' dbQuoteString(conn, x, ...) ## S4 method for signature 'TrinoConnection,SQL' dbQuoteString(conn, x, ...)## S4 method for signature 'TrinoConnection,character' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'TrinoConnection,SQL' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'TrinoConnection,character' dbQuoteString(conn, x, ...) ## S4 method for signature 'TrinoConnection,SQL' dbQuoteString(conn, x, ...)
conn |
A TrinoConnection object. |
x |
A character vector, or an identifier for |
... |
Unused, for compatibility with the generic. |
A DBI::SQL object.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbQuoteIdentifier(con, "my column") DBI::dbQuoteString(con, "O'Brien") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbQuoteIdentifier(con, "my column") DBI::dbQuoteString(con, "O'Brien") DBI::dbDisconnect(con)
Turns R values into SQL literals Trino accepts where a value of the matching
type is expected. Used by DBI::sqlInterpolate() and glue::glue_sql(), and
so the way to put values into a statement, since RTrino has no parameter
binding. Missing values become NULL.
## S4 method for signature 'TrinoConnection' dbQuoteLiteral(conn, x, ...)## S4 method for signature 'TrinoConnection' dbQuoteLiteral(conn, x, ...)
conn |
A TrinoConnection object. |
x |
A vector to quote. |
... |
Unused, for compatibility with the generic. |
character and factor: 'text', with embedded quotes doubled;
logical: TRUE or FALSE;
integer and integer64: the integer's digits;
double: a DOUBLE literal that reads back as the same double, such as
0.30000000000000004E0, or nan(), infinity() or -infinity();
Date: DATE '2026-01-15';
POSIXct: TIMESTAMP '2026-01-15 10:30:00.123456', the instant as a
wall-clock time in the connection's session.timezone, which is how Trino
reads it back;
a list of raw vectors: X'0102FF'.
Other classes are quoted by DBI's default method.
A DBI::SQL object.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbQuoteLiteral(con, as.Date("2026-01-15")) DBI::sqlInterpolate( con, "SELECT * FROM orders WHERE orderdate >= ?since AND urgent = ?flag", since = as.Date("2026-01-01"), flag = TRUE ) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") DBI::dbQuoteLiteral(con, as.Date("2026-01-15")) DBI::sqlInterpolate( con, "SELECT * FROM orders WHERE orderdate >= ?since AND urgent = ?flag", since = as.Date("2026-01-01"), flag = TRUE ) DBI::dbDisconnect(con)
Drop a table
## S4 method for signature 'TrinoConnection,character' dbRemoveTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbRemoveTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbRemoveTable(conn, name, ...)## S4 method for signature 'TrinoConnection,character' dbRemoveTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,Id' dbRemoveTable(conn, name, ...) ## S4 method for signature 'TrinoConnection,ANY' dbRemoveTable(conn, name, ...)
conn |
A TrinoConnection object. |
name |
Table name, in any form |
... |
Unused, for compatibility with the generic. |
TRUE, invisibly.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3)) DBI::dbRemoveTable(con, "sales") DBI::dbExistsTable(con, "sales") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3)) DBI::dbRemoveTable(con, "sales") DBI::dbExistsTable(con, "sales") DBI::dbDisconnect(con)
Not a DBI generic: DBI has no dbRenameTable(), so RTrino defines its
own, the way RPresto does for Presto.
dbRenameTable(conn, name, new_name, ...) ## S4 method for signature 'TrinoConnection' dbRenameTable(conn, name, new_name, ...)dbRenameTable(conn, name, new_name, ...) ## S4 method for signature 'TrinoConnection' dbRenameTable(conn, name, new_name, ...)
conn |
A TrinoConnection object. |
name |
Current table name, in any form |
new_name |
New table name, in the same forms. |
... |
Unused, for compatibility with the generic. |
TRUE, invisibly.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3)) dbRenameTable(con, "sales", "sales_old") DBI::dbExistsTable(con, "sales_old") DBI::dbRemoveTable(con, "sales_old") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3)) dbRenameTable(con, "sales", "sales_old") DBI::dbExistsTable(con, "sales_old") DBI::dbRemoveTable(con, "sales_old") DBI::dbDisconnect(con)
Posts the statement to /v1/statement and returns immediately with a
TrinoResult cursor; the rows are pulled by dbFetch(). A statement
that fails during planning raises an error here, because Trino reports it in
the response to the initial POST.
## S4 method for signature 'TrinoConnection,character' dbSendQuery(conn, statement, ...)## S4 method for signature 'TrinoConnection,character' dbSendQuery(conn, statement, ...)
conn |
A TrinoConnection object. |
statement |
A single SQL statement, without a trailing semicolon. |
... |
Unused, for compatibility with the generic. |
Query parameters are not supported: passing params is an error rather
than being silently ignored. Put values into the statement with
DBI::sqlInterpolate() or glue::glue_sql(), which quote them with
DBI::dbQuoteLiteral() as Trino literals.
A TrinoResult object.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") res <- DBI::dbSendQuery(con, "SELECT 1 AS n") DBI::dbFetch(res) DBI::dbClearResult(res) # Values go into the SQL as literals, quoted for Trino sql <- DBI::sqlInterpolate( con, "SELECT count(*) AS n FROM orders WHERE orderdate >= ?since", since = as.Date("1998-01-01") ) DBI::dbGetQuery(con, sql) DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "tpch", schema = "tiny") res <- DBI::dbSendQuery(con, "SELECT 1 AS n") DBI::dbFetch(res) DBI::dbClearResult(res) # Values go into the SQL as literals, quoted for Trino sql <- DBI::sqlInterpolate( con, "SELECT count(*) AS n FROM orders WHERE orderdate >= ?since", since = as.Date("1998-01-01") ) DBI::dbGetQuery(con, sql) DBI::dbDisconnect(con)
Unlike dbSendQuery(), runs
the statement to completion before returning, so that
dbGetRowsAffected() answers straight away, as DBI requires: Trino only
reports the count once the statement has finished.
## S4 method for signature 'TrinoConnection,character' dbSendStatement(conn, statement, ...)## S4 method for signature 'TrinoConnection,character' dbSendStatement(conn, statement, ...)
conn |
A TrinoConnection object. |
statement |
A single SQL statement, without a trailing semicolon. |
... |
Unused, for compatibility with the generic. |
A TrinoResult object whose statement has finished.
Creates the table with dbCreateTable() and fills it with
dbAppendTable(). CREATE TABLE cannot be undone by dbRollback() on
most connectors, so overwrite = TRUE plays it safe on its own: it
renames the existing table rather than dropping it, and restores it if
anything fails before the new table is fully written.
## S4 method for signature 'TrinoConnection,ANY' dbWriteTable( conn, name, value, ..., overwrite = FALSE, append = FALSE, field.types = NULL, temporary = FALSE, row.names = NULL, chunk_size = 1000L ) ## S4 method for signature 'TrinoConnection,Id' dbWriteTable(conn, name, value, ...)## S4 method for signature 'TrinoConnection,ANY' dbWriteTable( conn, name, value, ..., overwrite = FALSE, append = FALSE, field.types = NULL, temporary = FALSE, row.names = NULL, chunk_size = 1000L ) ## S4 method for signature 'TrinoConnection,Id' dbWriteTable(conn, name, value, ...)
conn |
A TrinoConnection object. |
name |
Table name, in any form |
value |
A data frame to write. |
... |
Unused, for compatibility with the generic. |
overwrite |
Drop and recreate the table if it already exists. |
append |
Add to the table if it already exists, instead of creating it. |
field.types |
A named character vector of Trino types, overriding
the types |
temporary |
Must be |
row.names |
Unused: RTrino never writes row names as a column. |
chunk_size |
Passed to |
TRUE, invisibly.
con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3, label = letters[1:3])) DBI::dbWriteTable(con, "sales", data.frame(id = 4L, label = "d"), append = TRUE) DBI::dbGetQuery(con, "SELECT * FROM sales ORDER BY id") # Replace the table and its contents DBI::dbWriteTable(con, "sales", data.frame(id = 9L, label = "z"), overwrite = TRUE) DBI::dbGetQuery(con, "SELECT * FROM sales") DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)con <- DBI::dbConnect(RTrino::Trino(), host = Sys.getenv("RTRINO_TEST_URL"), catalog = "memory", schema = "default") DBI::dbWriteTable(con, "sales", data.frame(id = 1:3, label = letters[1:3])) DBI::dbWriteTable(con, "sales", data.frame(id = 4L, label = "d"), append = TRUE) DBI::dbGetQuery(con, "SELECT * FROM sales ORDER BY id") # Replace the table and its contents DBI::dbWriteTable(con, "sales", data.frame(id = 9L, label = "z"), overwrite = TRUE) DBI::dbGetQuery(con, "SELECT * FROM sales") DBI::dbRemoveTable(con, "sales") DBI::dbDisconnect(con)
Creates the driver object passed as the first argument to
DBI::dbConnect(). The call has no side effects and always succeeds.
Trino()Trino()
A TrinoDriver object.
drv <- Trino() drvdrv <- Trino() drv
Each helper returns a closure that takes an httr2 request and returns it
with the appropriate credentials attached. The credentials live only in that
closure's environment, so they are never written to the global environment
and never stored on the connection object in plain sight. Pass the result as
the auth argument of dbConnect().
trino_auth_basic(user, password) trino_auth_jwt(token) trino_auth_oauth2(client_id, client_secret, token_url, scope = NULL, ...)trino_auth_basic(user, password) trino_auth_jwt(token) trino_auth_oauth2(client_id, client_secret, token_url, scope = NULL, ...)
user |
User name. |
password |
Password. Read it from the environment
( |
token |
A JWT, as a string. |
client_id |
OAuth2 client id. |
client_secret |
OAuth2 client secret. |
token_url |
Token endpoint of the OAuth2 provider. |
scope |
Optional OAuth2 scope. |
... |
Further arguments passed on to
|
trino_auth_basic() — HTTP basic authentication, used by Trino's LDAP and
password-file authenticators.
trino_auth_jwt() — a bearer JWT, for service accounts and unattended
pipelines, or for a cluster fronted by an SSO proxy that mints its own
tokens.
trino_auth_oauth2() — OAuth2 client credentials, for corporate identity
providers such as Okta or Entra ID. httr2 caches the token and renews it
when it expires.
Trino rejects basic and bearer credentials over plain HTTP, so use an
https:// host with all three.
A function of one argument (an httr2 request) returning a modified
request.
# Only builds the credential; nothing is sent until a connection uses it auth <- trino_auth_basic("analyst", Sys.getenv("TRINO_PASSWORD")) # Needs a cluster that authenticates with a password ## Not run: con <- DBI::dbConnect( RTrino::Trino(), host = "https://trino.example.com", port = 443, user = "analyst", catalog = "hive", schema = "default", auth = auth ) ## End(Not run)# Only builds the credential; nothing is sent until a connection uses it auth <- trino_auth_basic("analyst", Sys.getenv("TRINO_PASSWORD")) # Needs a cluster that authenticates with a password ## Not run: con <- DBI::dbConnect( RTrino::Trino(), host = "https://trino.example.com", port = 443, user = "analyst", catalog = "hive", schema = "default", auth = auth ) ## End(Not run)
Collects the TLS settings applied to every request made on a connection.
Pass the result as the ssl_options argument of dbConnect().
trino_ssl(verify = TRUE, ca_bundle = NULL)trino_ssl(verify = TRUE, ca_bundle = NULL)
verify |
Whether to verify the server's certificate. Defaults to |
ca_bundle |
Path to a PEM file holding the certificate authorities to
trust, or |
A cluster whose certificate is signed by an internal authority does not need
verification turned off: point ca_bundle at the authority's PEM file and
certificates keep being checked. verify = FALSE accepts any certificate,
including an attacker's, and so dbConnect() warns once when it opens a
connection with it.
A list of TLS options.
# Secure default trino_ssl() # Trust an internal certificate authority ## Not run: trino_ssl(ca_bundle = "/etc/ssl/certs/internal-ca.pem") ## End(Not run)# Secure default trino_ssl() # Trust an internal certificate authority ## Not run: trino_ssl(ca_bundle = "/etc/ssl/certs/internal-ca.pem") ## End(Not run)
Reports the R type a column of the given Trino type is converted to. Mostly
useful for documentation and testing; dbFetch() converts columns through
trino_cast_column().
trino_type_to_r(type, bigint = c("integer64", "numeric", "character"))trino_type_to_r(type, bigint = c("integer64", "numeric", "character"))
type |
A Trino type name, with or without parameters, as a single string. |
bigint |
How |
A string naming an R class.
trino_type_to_r("varchar(10)") trino_type_to_r("bigint") trino_type_to_r("bigint", bigint = "numeric") trino_type_to_r("timestamp(3) with time zone")trino_type_to_r("varchar(10)") trino_type_to_r("bigint") trino_type_to_r("bigint", bigint = "numeric") trino_type_to_r("timestamp(3) with time zone")