avatica

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package avatica is a database/sql driver for Apache Calcite Avatica, which carries the calls of JDBC over HTTP to a server that runs them on a database behind it. It serves the standalone server of Avatica and the Apache Phoenix Query Server, over JSON (D153). It registers the one name "avatica", and takes a DSN of the form avatica://user:pass@host:8765 (D156).

db, err := sql.Open("avatica", "avatica://SA@localhost:8765")

One connection of database/sql is one connection of Avatica, with autoCommit on (D157). A query reads its rows in frames, one token at a time, and fetches each next frame (D157). The server binds each argument as a typed value (D158). A value has the Go type that fits the name of its type of JDBC (D155). Transactions are those of the database behind the server, and the server has no way to stop a statement (D159). docs/AVATICA.md holds what the driver knows about the server.

Index

Constants

View Source
const (
	// AuthNone sends the user and the password in the info of
	// openConnection only. It is the default.
	AuthNone = "none"
	// AuthBasic also sends them by HTTP basic authentication, for a server
	// that checks them itself.
	AuthBasic = dbimp.AuthBasic
)

The values of the key auth, which say whether the driver also sends the user and the password by HTTP basic authentication (D156).

View Source
const Name = "avatica"

Name is the name that the driver registers with database/sql, and the scheme of its DSN.

Variables

This section is empty.

Functions

func WithOptions

func WithOptions(ctx context.Context, opts ...Option) context.Context

WithOptions returns a context that carries opts. Each statement started with the context applies them after the options of the DSN.

Types

type Config

type Config struct {
	// Host is the host of the server.
	Host string
	// Port is the port of the server, 8765 by default.
	Port int
	// TLS is true to speak HTTPS.
	TLS bool
	// User and Password are the credentials, which go in the info of
	// openConnection, to the database behind the server.
	User     string
	Password string
	// Auth is AuthNone or AuthBasic (D156).
	Auth string
}

Config is the configuration of a connector, which the DSN holds. The caller owns it (D7).

func ParseDSN

func ParseDSN(dsn string) (*Config, error)

ParseDSN parses a DSN of the form avatica://user:pass@host:port?key=value (D27, D35 and D156). A DSN with a path is refused.

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

FormatDSN returns the DSN of cfg. ParseDSN reads it back as cfg, for a Config that ParseDSN or NewConnector filled.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector opens connections to one server. 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

func NewConnector(cfg Config) *Connector

NewConnector returns a Connector for cfg. The connector keeps a copy of cfg, and fills each field that is zero with its default.

func (*Connector) Close

func (c *Connector) Close() error

Close closes the idle connections of the transport.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

Connect satisfies driver.Connector. It opens a connection of Avatica with an id of its own, and sets autoCommit on, because the Phoenix Query Server opens one with it off (D157).

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver satisfies driver.Connector.

type Driver

type Driver struct{}

Driver is the database/sql driver for Avatica.

func (Driver) Open

func (Driver) Open(string) (driver.Conn, error)

Open satisfies driver.Driver. database/sql opens a connection through OpenConnector, and Open returns an error, because opening a connection needs a context.

func (Driver) OpenConnector

func (Driver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector satisfies driver.DriverContext. It parses the DSN.

type Error

type Error struct {
	// HTTPStatus is the status code of the response.
	HTTPStatus int
	// Message is the message of the server: errorMessage, or the first line
	// of the first exception when the server sent none.
	Message string
	// Code is errorCode, such as 1 for an unknown connection.
	Code int
	// SQLState is sqlState, which HSQLDB leaves as 00000.
	SQLState string
	// Exception is the first line of the first exception, such as
	// java.sql.SQLSyntaxErrorException: unexpected token: SELEC.
	Exception string
	// contains filtered or unexported fields
}

Error is an error that the server of Avatica reported. It arrives with HTTP 500, as {"response": "error", "exceptions": [...], "errorMessage": ..., "errorCode": ..., "sqlState": ..., "severity": ...} (measured).

func (*Error) Error

func (err *Error) Error() string

Error satisfies the error interface.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap returns the *dbimp.StatusError of a response whose status is not 2xx, or nil.

type Option

type Option = dbimp.Option[options]

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

func WithDatabase(name string) Option

WithDatabase would choose the schema of one statement. The schema is a property of the connection of Avatica, which one statement cannot change, so a statement with it fails with dbimp.ErrNotSupported. The SQL can name the schema of each table.

func WithFrameSize

func WithFrameSize(rows int) Option

WithFrameSize sets the count of rows of each frame that the driver asks for, 1000 by default (D157).

func WithParameter

func WithParameter(name string, value any) Option

WithParameter sets any key of the request that runs the statement by its name, such as "maxRowCount". The value is encoded with json/v2. A key named here replaces one that the driver sets itself.

func WithReadonly

func WithReadonly(readonly bool) Option

WithReadonly would make the server refuse a write of one statement. readOnly is a property of the connection of Avatica, which one statement cannot change, so WithReadonly(true) fails with dbimp.ErrNotSupported. BeginTx with ReadOnly makes a transaction read-only (D159).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout would bound the time of the statement on the server. Avatica has none, and the server runs a query to its end when its client leaves (measured), so a timeout above zero fails with dbimp.ErrNotSupported. The context of the statement still stops its request and its read (D159).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL