gohive

package module
v0.0.0-...-4667d1f Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2018 License: MIT Imports: 19 Imported by: 0

README

gohive

hive driver with pure go implementation
its development is delayed for hiveserver2 need sasl library and there's no good one for go

Documentation

Index

Constants

View Source
const (
	// HiveAuthNoSasl indicate no sasl need here
	HiveAuthNoSasl = "nosasl"
	// HiveAuthPlain is the default sasl mechanism
	HiveAuthPlain = "plain"
	// HiveAuthKerberos indicate kerberos sasl mechanism need here
	HiveAuthKerberos = "kerberos"
)
View Source
const (
	DEFAULT_HOST        = "locahost"
	DEFAULT_PORT        = 10000
	HIVE_2              = "hive2"
	PARAM_DIAL_TIMEOUT  = "dialTimeout"
	PARAM_EXEC_TIMEOUT  = "execTimeout"
	PARAM_AUTH          = "auth"
	PARAM_KERBEROS_NAME = "kerberos_name"
	PARAM_RUN_ASYNC     = "runAsync"
)
View Source
const (
	AUTH_LDAP     = "ldap"
	AUTH_KERBEROS = "kerberos"
)
View Source
const (
	HIVE_DRIVER_NAME = "hive"
)

Variables

View Source
var (
	DefaultTimeout                  = 30 * int64(math.Pow10(9))
	ERROR_INVALID_SCHEME            = errors.New("Hive: Invalid scheme, only hive2 supported")
	ERROR_INVALID_CONNECTION_STRING = errors.New("Hive: Invalid connection string")
	ERROR_INVALID_PORT              = errors.New("Hive: Invalid port in connection string")
	ERROR_INVALID_DATABASE_NAME     = errors.New("Hive: Invalid database name")
	ERROR_INVALID_AUTH_TYPE         = errors.New("Hive: Invalid auth type")
	ERROR_INVALID_DIAL_TIMEOUT      = errors.New("Hive: Invalid DialTimeout")
	ERROR_INVALID_EXEC_TIMEOUT      = errors.New("Hive: Invalid ExecTimeout")
	ERROR_INVALID_ASYNC_VALUE       = errors.New("Hive: Invalid async value, must be true or false")
)
View Source
var (
	ERROR_NOT_SUPPORTED            = fmt.Errorf("Hive: Not supported")
	ERROR_NOT_IMPLEMENTED          = fmt.Errorf("Hive: Not implemented")
	ERROR_PREPARED_QUERY_NOT_FOUND = fmt.Errorf("Hive: Prepared query not found")
	ERROR_INTERNAL                 = fmt.Errorf("Hive: Internal error")
)
View Source
var REFLECT_MAP = map[string]reflect.Type{
	"BOOLEAN":             reflect.TypeOf(true),
	"TINYINT":             reflect.TypeOf(int8(0)),
	"SMALLINT":            reflect.TypeOf(int16(0)),
	"INT":                 reflect.TypeOf(int(0)),
	"BIGINT":              reflect.TypeOf(int64(0)),
	"FLOAT":               reflect.TypeOf(float32(0)),
	"DOUBLE":              reflect.TypeOf(float64(0)),
	"STRING":              reflect.TypeOf(string("")),
	"TIMESTAMP":           reflect.TypeOf(int(0)),
	"BINARY":              reflect.TypeOf([]byte{}),
	"ARRAY":               reflect.TypeOf([]interface{}{}),
	"MAP":                 reflect.TypeOf(map[string]interface{}{}),
	"STRUCT":              reflect.TypeOf(map[string]interface{}{}),
	"UNIONTYPE":           nil,
	"DECIMAL":             reflect.TypeOf(int(0)),
	"NULL":                reflect.TypeOf(nil),
	"DATE":                reflect.TypeOf(time.Time{}),
	"VARCHAR":             reflect.TypeOf(string("")),
	"CHAR":                reflect.TypeOf(rune(' ')),
	"INTERVAL_YEAR_MONTH": reflect.TypeOf(time.Time{}),
	"INTERVAL_DAY_TIME":   reflect.TypeOf(time.Time{}),
}

REFLECT_MAP is type map from hive to golang

Functions

func NamedValueToValue

func NamedValueToValue(args []driver.NamedValue) []driver.Value

NamedValueToValue parse NamedValue into Value

func NewPairResultChan

func NewPairResultChan() chan *PairResult

NewPairResultChan make a new chan for PairResult

func RegisterDial

func RegisterDial(net string, dial DialFunc)

RegisterDial registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. addr is passed as a parameter to the dial function.

func SplitWith

func SplitWith(data string, sep rune) []string

SplitWith split the given string with sep according to sql syntax

func VerifySuccess

func VerifySuccess(status *rpc.TStatus, withInfo bool) error

VerifySuccess verifies if the status is success

func WithLock

func WithLock(lock *sync.Mutex, f func())

WithLock execute f with given lock

Types

type Config

type Config struct {
	Scheme       string
	Host         string
	Port         int64
	User         string
	Password     string
	DBName       string
	DialTimeout  time.Duration
	ExecTimeout  time.Duration
	Auth         string
	KerberosName string
	RunAsync     bool
}

func NewConfig

func NewConfig() *Config

func ParseDSN

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

func (*Config) Address

func (cfg *Config) Address() string

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

type DialFunc

type DialFunc func(addr string) (net.Conn, error)

DialFunc is a function which can be used to establish the network connection. Custom dial functions must be registered with RegisterDial

type HiveConn

type HiveConn struct {
	Config          *Config
	Transport       thrift.TTransport
	Client          *rpc.TCLIServiceClient
	SessionHandle   *rpc.TSessionHandle
	OperationHandle *rpc.TOperationHandle
	// contains filtered or unexported fields
}

HiveConn implements driver.Conn

func NewHiveConn

func NewHiveConn(dsn string) (*HiveConn, error)

NewHiveConn build a new driver.Conn with the given dsn

func (*HiveConn) Begin deprecated

func (conn *HiveConn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

Deprecated: Drivers should implement ConnBeginTx instead (or additionally).

func (*HiveConn) Close

func (conn *HiveConn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

func (*HiveConn) Exec deprecated

func (conn *HiveConn) Exec(query string, args []driver.Value) (driver.Result, error)

Exec is an optional interface that may be implemented by a Conn.

If a Conn does not implement Execer, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement.

Exec may return ErrSkip.

Deprecated: Drivers should implement ExecerContext instead (or additionally).

func (*HiveConn) ExecContext

func (conn *HiveConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

ExecContext is an optional interface that may be implemented by a Conn.

If a Conn does not implement ExecerContext, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement.

ExecerContext may return ErrSkip.

ExecerContext must honor the context timeout and return when the context is canceled.

func (*HiveConn) Ping

func (conn *HiveConn) Ping(ctx context.Context) error

Ping is an optional interface that may be implemented by a Conn.

If a Conn does not implement Pinger, the sql package's DB.Ping and DB.PingContext will check if there is at least one Conn available.

If Conn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove the Conn from pool.

func (*HiveConn) Prepare

func (conn *HiveConn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

func (*HiveConn) Query deprecated

func (conn *HiveConn) Query(query string, args []driver.Value) (driver.Rows, error)

Query is an optional interface that may be implemented by a Conn.

If a Conn does not implement Queryer, the sql package's DB.Query will first prepare a query, execute the statement, and then close the statement.

Query may return ErrSkip.

Deprecated: Drivers should implement QueryerContext instead (or additionally).

func (*HiveConn) QueryContext

func (conn *HiveConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext is an optional interface that may be implemented by a Conn.

If a Conn does not implement QueryerContext, the sql package's DB.Query will first prepare a query, execute the statement, and then close the statement.

QueryerContext may return ErrSkip.

QueryerContext must honor the context timeout and return when the context is canceled.

type HiveDriver

type HiveDriver struct {
}

HiveDriver implements sql.driver

func (*HiveDriver) Open

func (d *HiveDriver) Open(dsn string) (driver.Conn, error)

Open new Connection.

type HiveResult

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

HiveResult is the result of a query execution.

func (*HiveResult) LastInsertId

func (r *HiveResult) LastInsertId() (int64, error)

LastInsertId returns the database's auto-generated ID after, for example, an INSERT into a table with primary key.

func (*HiveResult) RowsAffected

func (r *HiveResult) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected by the query.

type HiveRows

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

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

func (*HiveRows) Close

func (r *HiveRows) Close() error

Close closes the rows iterator.

func (*HiveRows) ColumnTypeDatabaseTypeName

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

ColumnTypeDatabaseTypeName may be implemented by Rows. It should return the database system type name without the length. Type names should be uppercase. Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT", "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML", "TIMESTAMP".

func (*HiveRows) ColumnTypeScanType

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

ColumnTypeScanType may be implemented by Rows. It should return the value type that can be used to scan types into. For example, the database column type "bigint" this should return "reflect.TypeOf(int64(0))".

func (*HiveRows) Columns

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

Columns returns the names of the columns. The number of columns of the result is inferred from the length of the slice. If a particular column name isn't known, an empty string should be returned for that entry.

func (*HiveRows) GetQueryLog

func (r *HiveRows) GetQueryLog() ([]string, error)

GetQueryLog returns the logs generated when query running

func (*HiveRows) Next

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

Next is called to populate the next row of data into the provided slice. The provided slice will be the same size as the Columns() are wide.

Next should return io.EOF when there are no more rows.

type HiveStatement

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

HiveStatement is a prepared statement. It is bound to a Conn and not used by multiple goroutines concurrently.

func NewHiveStatement

func NewHiveStatement(conn *HiveConn, query string) (*HiveStatement, error)

NewHiveStatement create a new driver.stmt with the given conn

func (*HiveStatement) CheckNamedValue

func (stmt *HiveStatement) CheckNamedValue(value *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 (*HiveStatement) Close

func (stmt *HiveStatement) Close() error

Close closes the statement.

As of Go 1.1, a Stmt will not be closed if it's in use by any queries.

func (*HiveStatement) Exec deprecated

func (stmt *HiveStatement) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

Deprecated: Drivers should implement StmtExecContext instead (or additionally).

func (*HiveStatement) ExecContext

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

ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.

ExecContext must honor the context timeout and return when it is canceled.

func (*HiveStatement) NumInput

func (stmt *HiveStatement) NumInput() int

NumInput returns the number of placeholder parameters.

If NumInput returns >= 0, the sql package will sanity check argument counts from callers and return errors to the caller before the statement's Exec or Query methods are called.

NumInput may also return -1, if the driver doesn't know its number of placeholders. In that case, the sql package will not sanity check Exec or Query argument counts.

func (*HiveStatement) Query deprecated

func (stmt *HiveStatement) Query(args []driver.Value) (rows driver.Rows, _ error)

Query executes a query that may return rows, such as a SELECT.

Deprecated: Drivers should implement StmtQueryContext instead (or additionally).

func (*HiveStatement) QueryContext

func (stmt *HiveStatement) QueryContext(ctx context.Context, args []driver.NamedValue) (rows driver.Rows, _ error)

QueryContext executes a query that may return rows, such as a SELECT.

QueryContext must honor the context timeout and return when it is canceled.

type PairResult

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

PairResult represents common func result

Directories

Path Synopsis
hive_service
rpc

Jump to

Keyboard shortcuts

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