hive

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hive is a database/sql driver for Apache Hive and Apache Impala. Both serve the Thrift service TCLIService of HiveServer2, and this driver speaks it over HTTP, in the binary protocol of Thrift that the root package writes (D232). It registers the one name "hive", with Impala as a flavor of it (D233), and takes a DSN of the form hive://user:pass@host:10001/database?httpPath=cliservice (D234).

db, err := sql.Open("hive", "hive://hive:secret@localhost:10001")

A connection is one session of HiveServer2. A statement runs as an operation: the driver sends it, waits until it ends, and reads the rows page by page, one page of 1000 rows at a time (D235). The server binds no parameter, so the driver writes each argument into the text of the statement as a literal. The driver has no transactions. docs/HIVE.md holds what the driver knows about the servers.

Index

Constants

View Source
const Name = "hive"

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 HTTP port of the server, 10001 by default.
	Port int
	// TLS is true to speak HTTPS.
	TLS bool
	// User and Password are the credentials, which go by HTTP Basic
	// authentication. With no user, the driver sends the user "anonymous".
	User     string
	Password string
	// Database is the database of the session, or "" for the default of the
	// server.
	Database string
	// HTTPPath is the path of the endpoint, "cliservice" by default.
	HTTPPath 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 hive://user:pass@host:port/database?key=value (D27, D35 and D234). It refuses a key that it does not know, and a key that repeats.

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 session, and asks the server which flavor it is.

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 Hive and Impala.

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 {
	// SQLState is the SQLSTATE of the server, or "".
	SQLState string
	// Code is the native code of the server, or 0.
	Code int32
	// Message is the message of the server.
	Message string
	// Info holds the info messages of the status, such as "Server-side error;
	// please check HS2 logs.".
	Info []string
	// HTTPStatus is the status code of the response, or 0 for an error that
	// arrived with HTTP 200.
	HTTPStatus int
	// contains filtered or unexported fields
}

Error is an error that HiveServer2 reported. A statement that does not compile fails at ExecuteStatement with HTTP 200 and a TStatus whose status code is 3. A statement that fails while it runs shows in the state ERROR of GetOperationStatus, with the same fields. A request that the server refused has another HTTP status, such as 401 for a request with no credential, and a call that the server cannot run is a Thrift exception (measured, docs/HIVE.md, Errors).

func (*Error) AuthenticationRefused

func (err *Error) AuthenticationRefused() bool

AuthenticationRefused reports whether the server refused the credential. It returns what Is reports for dbimp.ErrAuthentication, and a caller that does not import this module reads it through an interface of its own (D227).

func (*Error) ErrVerbose

func (err *Error) ErrVerbose(_ string) string

ErrVerbose returns the error as psql writes it for \errverbose: the SQLSTATE, or the native code when there is none, and the message on the first line, and then each field that the server sent, one on each line with its name in upper case. A caller that does not import this module reads it through an interface of its own (D231).

func (*Error) Error

func (err *Error) Error() string

Error satisfies the error interface.

func (*Error) Is

func (err *Error) Is(target error) bool

Is reports whether err matches target. It matches dbimp.ErrAuthentication for HTTP 401, which Hive answers to a request with no credential (recorded: "no credentials"). Both servers accept any user and any password, so no other answer means a refused credential (D197).

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 a database for one statement. The database is a state of the session, which another statement of the connection would see, so a statement with it fails with dbimp.ErrNotSupported. The DSN names the database of the session.

func WithFetchSize

func WithFetchSize(n int) Option

WithFetchSize sets the number of rows that each FetchResults asks for. The default is 1000.

func WithParameter

func WithParameter(name string, value any) Option

WithParameter sets a key of confOverlay of ExecuteStatement by its name, such as "hive.exec.parallel" on Hive, with the text of value. The server applies it to this statement only.

func WithReadonly

func WithReadonly(readonly bool) Option

WithReadonly would send the statement on a read-only connection. Neither flavor has such a setting, so a statement with WithReadonly(true) fails with dbimp.ErrNotSupported.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the time that the driver gives the statement, from its start to the end of its rows. When the time ends, the driver sends CancelOperation and the statement fails with context.DeadlineExceeded. When the context has a deadline too, the shorter of the two goes. Zero sets no timeout.

Jump to

Keyboard shortcuts

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