hive

package module
v0.0.0-...-89c0eda Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 12 Imported by: 0

README

gohive

克隆自 https://github.com/derekgr/hivething
更改了TCLIService, 在inf/目录下,并修改了相应的调用。支持Hive1.2+版本
支持thrift 0.11版本

Usage

package main

import (
	"fmt"

	"github.com/jasonlabz/hive/driver"
)

func main() {
	//	conn, err := gohive.Connect("127.0.0.1:10000", gohive.DefaultOptions) // 无用户名、密码
	conn, err := gohive.ConnectWithUser("127.0.0.1:10000", "username", "password", gohive.DefaultOptions) // 需要用户名、密码
	if err != nil {
		fmt.Errorf("Connect error %v", err)
	}

	_, err = conn.Exec("create table if not exists t(c1 int)")
	_, err = conn.Exec(" insert into default.t values(1), (2)")
	if err != nil {
		fmt.Errorf("Connection.Exec error: %v", err)
	}
	rs, err := conn.Query("select c1 from t limit 10")
	if err != nil {
		fmt.Errorf("Connection.Query error: %v", err)
	}
	var c1 int
	for rs.Next() {
		rs.Scan(&c1)
		fmt.Println(c1)
	}
	conn.Close()
}

hive

Documentation

Overview

Package driver wraps the hiveserver2 thrift interface in a few related interfaces for more convenient use.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultOptions = Options{
		PollIntervalSeconds: 5,
		BatchSize:           10000,
		ConnectTimeout:      5000,
		SocketTimeout:       5000,
	}
)

Functions

func ParseParams

func ParseParams(query string) (string, int)

ParseParams rewrites the query from using "?" placeholders to using "@pN" parameter names that SQL Server will accept.

This function and package is not subject to any API compatibility guarantee.

Types

type Connection

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

func Connect

func Connect(hostPort string, options Options) (*Connection, error)

func ConnectWithUser

func ConnectWithUser(hostPort, username, password string, options Options) (*Connection, error)

func (*Connection) Close

func (c *Connection) Close() error

Close Closes an open hive session. After using this, the connection is invalid for other use.

func (*Connection) Exec

func (c *Connection) Exec(query string) (*inf.TExecuteStatementResp, error)

func (*Connection) Query

func (c *Connection) Query(query string) (RowSet, error)

Query Issue a query on an open connection, returning a RowSet, which can be later used to query the operation's status.

type Options

type Options struct {
	PollIntervalSeconds int64
	BatchSize           int64

	Host               string
	Port               int
	Username           string
	Password           string
	Database           string
	MaxMessageSize     int32
	MaxFrameSize       int32
	ConnectTimeout     time.Duration
	SocketTimeout      time.Duration
	TLSConfig          *tls.Config
	TBinaryStrictRead  *bool
	TBinaryStrictWrite *bool
	THeaderProtocolID  *thrift.THeaderProtocolID
}

Options for opened Hive sessions.

type RowSet

type RowSet interface {
	Handle(ctx context.Context) ([]byte, error)
	Columns() []string
	Next() bool
	Scan(dest ...interface{}) error
	Poll() (*Status, error)
	Wait() (*Status, error)
}

A RowSet represents an asyncronous hive operation. You can Reattach to a previously submitted hive operation if you have a valid thrift client, and the serialized Handle() from the prior operation.

type Status

type Status struct {
	Error error
	At    time.Time
	// contains filtered or unexported fields
}

Represents job status, including success state and time the status was updated.

func (Status) IsComplete

func (s Status) IsComplete() bool

Returns true if the job has completed or failed.

func (Status) IsSuccess

func (s Status) IsSuccess() bool

Returns true if the job compelted successfully.

func (Status) String

func (s Status) String() string

Returns a string representation of operation status.

Directories

Path Synopsis
inf

Jump to

Keyboard shortcuts

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