dbsql

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 19 Imported by: 31

README

Databricks SQL Driver for Go (Beta)

Description

This repo contains a Databricks SQL Driver for Go's database/sql package. It can be used to connect and query Databricks clusters and SQL Warehouses. This project is a fork of go-impala.

NOTE: This Driver is Beta.

Documentation

Full documentation is not yet available. See below for usage examples.

Usage

import (
	"database/sql"
	"time"

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

db, err := sql.Open("databricks", "databricks://:dapi********@********.databricks.com/sql/1.0/endpoints/********")
if err != nil {
	panic(err)
}


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

Additional usage examples are available here.

DSN (Data Source Name)

The DSN format is:

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 per network request by setting the maxRows query parameter:

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

Testing

Unit Tests
go test
e2e Tests

To run tests against a SQL warehouse, you need to pass a DSN environment variable first:

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

Issues

If you find any issues, feel free to create an issue or send a pull request directly.

Contributing

See CONTRIBUTING.md

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	TimeFmt = "2006-01-02T15:04:05.999-07:00"
)

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 EscapeArg added in v0.1.3

func EscapeArg(arg driver.NamedValue) (string, error)

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