dbsql

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 19 Imported by: 26

README

Go Databricks SQL Driver

Databricks SQL driver for Go's database/sql package.

Usage

import (
	"database/sql"
	"time"

	_ "github.com/databricks/databricks-sql-go"
)

db, err := sql.Open("databricks", "databricks://:dapi-secret-token@example.cloud.databricks.com/sql/1.0/endpoints/12345a1b2c3d456f")
if err != nil {
	panic(err)
}


rows, err := db.Query("SELECT 1")

(see additional usage examples in examples)

DSN (Data Source Name)

The Data Source Name expected is of the following format:

databricks://:[your token]@[Workspace hostname][Endpoint HTTP Path]

You can set HTTP Timeout value by appending a timeout query parameter (in milliseconds) and you can set max rows to retrieve by setting the maxRows query parameter:

databricks://:[your token]@[Workspace hostname][Endpoint HTTP Path]?timeout=1000&maxRows=1000

Testing

To run only unit tests you can use go test, but if you want to run tests against a SQL endpoint, youw will need to pass a DSN environment variable:

$ DATABRICKS_DSN="databricks://:dapi-secret-token@example.cloud.databricks.com/sql/1.0/endpoints/12345a1b2c3d456f" go test

License

Apache 2.0.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultOptions for the driver
	DefaultOptions = Options{Port: "443", MaxRows: 10000, LogOut: ioutil.Discard}
)
View Source
var (
	// ErrNotSupported means this operation is not supported by the driver
	ErrNotSupported = errors.New("databricks: not supported")
)

Functions

func NewConnector

func NewConnector(opts *Options) driver.Connector

NewConnector creates connector with specified options

Types

type Conn

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

Connection

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

Begin is not supported

func (*Conn) CheckNamedValue

func (c *Conn) CheckNamedValue(val *driver.NamedValue) error

CheckNamedValue is called before passing arguments to the driver and is called in place of any ColumnConverter. CheckNamedValue must do type validation and conversion as appropriate for the driver.

func (*Conn) Close

func (c *Conn) Close() error

Close connection

func (*Conn) ExecContext

func (c *Conn) ExecContext(ctx context.Context, q string, args []driver.NamedValue) (driver.Result, error)

ExecContext executes a query that doesn't return rows

func (*Conn) OpenSession

func (c *Conn) OpenSession(ctx context.Context) (*hive.Session, error)

OpenSession ensure opened session

func (*Conn) Ping

func (c *Conn) Ping(ctx context.Context) error

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare returns prepared statement

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

PrepareContext returns prepared statement

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, q string, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes a query that may return rows

func (*Conn) ResetSession

func (c *Conn) ResetSession(ctx context.Context) error

ResetSession closes hive session

type Driver

type Driver struct{}

func (*Driver) Open

func (d *Driver) Open(uri string) (driver.Conn, error)

Open creates new connection to Databricks SQL

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(name string) (driver.Connector, error)

OpenConnector parses name and return connector with fixed options

type Options

type Options struct {
	Host     string
	Port     string
	Token    string
	HTTPPath string
	MaxRows  int64
	Timeout  int

	LogOut io.Writer
}

Options for driver connection

type Rows

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

Rows is an iterator over an executed query's results.

func (*Rows) Close

func (r *Rows) Close() error

Close closes rows iterator

func (*Rows) ColumnTypeDatabaseTypeName

func (r *Rows) ColumnTypeDatabaseTypeName(index int) string

ColumnTypeDatabaseTypeName returns column's database type name

func (*Rows) ColumnTypeScanType

func (r *Rows) ColumnTypeScanType(index int) reflect.Type

ColumnTypeScanType returns column's native type

func (*Rows) Columns

func (r *Rows) Columns() []string

Columns returns the names of the columns

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

Next prepares next row for scanning

type Stmt

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

Stmt is statement

func (*Stmt) CheckNamedValue

func (s *Stmt) CheckNamedValue(val *driver.NamedValue) error

CheckNamedValue is called before passing arguments to the driver and is called in place of any ColumnConverter. CheckNamedValue must do type validation and conversion as appropriate for the driver.

func (*Stmt) Close

func (s *Stmt) Close() error

Close statement. No-op

func (*Stmt) Exec

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

ExecContext executes a query that doesn't return rows

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput returns number of inputs

func (*Stmt) Query

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes a query that may return rows

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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