Documentation
¶
Overview ¶
Package trino is a database/sql driver for Trino and Presto, which run SQL over data that other systems hold, and take a statement over HTTP. It registers the one name "trino", and takes a DSN of the form trino://user@host:8080/catalog/schema?key=value (D175).
db, err := sql.Open("trino", "trino://user@localhost:8080/memory/default")
One driver serves both products. It asks GET /v1/info which one answered, and the key flavor of the DSN skips that request (D175). The driver sends a statement with POST /v1/statement, and polls the nextUri of each page until a page has none. It reads each page one token at a time. An error arrives in the body of a page with HTTP 200, and after some rows it wraps dbimp.ErrIncomplete (D107 and D175). The server runs a query on when its client leaves, so the driver sends DELETE to the nextUri when the caller closes the rows early and when the context ends (D175).
The driver sends each argument as a literal of EXECUTE name USING, on a statement that it names in the prepared-statement header (D175). It starts a transaction with START TRANSACTION and the transaction headers. The state of a session, such as USE and SET SESSION, stays on the connection, as the server asks in its response headers. docs/TRINO.md holds what the driver knows about the servers.
Index ¶
Constants ¶
const ( FlavorTrino = "trino" FlavorPresto = "presto" )
The two products that the driver serves, as the key flavor names them (D173 and D175).
const Name = "trino"
Name is the name that the driver registers with database/sql, and the scheme of its DSN.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Host is the host of the coordinator.
Host string
// Port is the port of the coordinator, 8080 by default and 8443 with
// TLS.
Port int
// TLS is true to speak HTTPS.
TLS bool
// User is the user of each statement. The servers need one. Password is
// the secret that the driver sends with basic authentication, if it is
// not empty.
User string
Password string
// Catalog and Schema are the catalog and the schema that a connection
// starts in. Each is empty to start in none, and Schema needs a Catalog.
Catalog string
Schema string
// Source is the source of each statement, which the server shows in its
// list of queries. It is "dbimp" by default.
Source string
// TimeZone is the time zone of each statement, which the driver sends as
// the header Time-Zone, such as UTC or Asia/Jakarta. It is empty by
// default, and the server uses its own.
TimeZone string
// Timeout is the time that the server gives each statement, which the
// driver sends as the session property query_max_execution_time. Zero
// sends none.
Timeout time.Duration
// Session holds the properties of the session that each connection
// starts with, from the keys session.<name> of the DSN.
Session map[string]string
// Flavor is FlavorTrino or FlavorPresto, and empty to ask the server
// with GET /v1/info.
Flavor string
}
Config is the configuration of a connector, which the DSN holds. The caller owns it (D7).
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector opens connections to one coordinator. It owns its transport, and every connection shares it. A caller can build one from a Config and open it with sql.OpenDB.
func NewConnector ¶
NewConnector returns a Connector for cfg. The connector keeps a copy of cfg, and fills each field that is zero with its default. Session is copied.
func (*Connector) Connect ¶
Connect satisfies driver.Connector. It asks the server which product it is, once, unless the DSN says. A connection holds its state on the client.
type Driver ¶
type Driver struct{}
Driver is the database/sql driver for Trino and Presto.
type Error ¶
type Error struct {
// HTTPStatus is the status code of the response, and 0 for an error that
// came in the body of a page.
HTTPStatus int
// Name is errorName, such as SYNTAX_ERROR or TABLE_NOT_FOUND, and empty
// for an error of the protocol.
Name string
// Type is errorType, such as USER_ERROR, and empty for an error of the
// protocol.
Type string
// Code is errorCode, a number that the product gives the name, and 0 for
// an error of the protocol.
Code int
// Message is message, or the text of the answer for an error of the
// protocol.
Message string
// Line and Column are the place of the error in the statement, from
// errorLocation, and 0 when the error has no place.
Line int
Column int
// contains filtered or unexported fields
}
Error is an error that Trino or Presto reported. A statement that fails answers HTTP 200 and a page with an error member, before any row or after some (measured). An error of the protocol has the status of HTTP, and a body of plain text or, on Presto, a page of HTML: HTTP 400 for an empty statement or a user that Presto lacks, HTTP 401 for a user that Trino lacks, HTTP 404 for a query or a token that the server does not know, and HTTP 410 for a nextUri that the client read before (measured).
type Option ¶
Option sets an option of one statement (D109). An option comes from the DSN, then from the context through WithOptions, then from an argument of the statement, and a later one wins.
func WithDatabase ¶
WithDatabase sets the catalog of one statement, as the first part of the path of the DSN does. Neither server has a database, and the catalog is the nearest name (D175).
func WithParameter ¶
WithParameter sets a property of the session for one statement by its name, such as "query_max_run_time", as the keys session.<name> of the DSN do. The servers take no body of keys, so the property of the session is the setting that a caller names. The value is written with fmt.Sprint. A property named here replaces the one of the connection, and a name that the server does not know fails the statement with INVALID_SESSION_PROPERTY (measured). WithParameter(name, nil) writes no value, and fails the statement with dbimp.ErrInvalidValue.
func WithReadonly ¶
WithReadonly asks that the statement write nothing. Neither server has a setting for one statement. A transaction can be read only, which BeginTx sets from sql.TxOptions, so WithReadonly(true) fails the statement with dbimp.ErrNotSupported (D109).
func WithSchema ¶
WithSchema sets the schema of one statement, as the second part of the path of the DSN does.
func WithSource ¶
WithSource sets the source of one statement, as the key source of the DSN does.
func WithTimeZone ¶
WithTimeZone sets the time zone of one statement, as the key timezone of the DSN does.
func WithTimeout ¶
WithTimeout sets the time that the server gives the statement, as the session property query_max_execution_time, as the key timeout of the DSN does. The server counts whole milliseconds, so the driver rounds d up to the next millisecond. The server stops a statement that runs longer with the error EXCEEDED_TIME_LIMIT (measured). Zero sends no timeout, and the server uses its own.