hive

package module
v0.0.0-...-d1d00c5 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

hive-go

WHAT

Go library for the Hive(WebHCat) API ref: https://cwiki.apache.org/confluence/display/Hive/WebHCat+Reference

Example

package main

import (
	"fmt"

	hive "github.com/3-shake/hive-go"
)

var cli *hive.Client

func init() {
	cli = hive.New("http://127.0.0.1", "50111", "hive")
}

func main() {
	database()
	table()
}

func table() {
	createTable()
}

func database() {
	createDatabase()
	listDatabase()
	showDatabase()
	dropDatabase()
}

func listDatabase() {
	res, err := cli.ListDatabase()
	fmt.Println(res, err)
}

func showDatabase() {
	res, err := cli.ShowDatabase("sample_hive")
	fmt.Println(res, err)
}

func createDatabase() {
	res, err := cli.CreateDatabase(fmt.Sprintf("sample_hive%d", 100), &hive.CreateDatabaseInput{})
	fmt.Println(res, err)
}

func dropDatabase() {
	res, err := cli.DropDatabase("sample_hive")
	fmt.Println(res, err)
}

func createTable() {
	res, err := cli.CreateTable("sample_hive", "sample_table", &hive.CreateTableInput{
		Comment: "test",
		Columns: []hive.Column{
			{"id", "int", ""},
			{"name", "string", ""},
		},
		PartitionBy: []hive.Column{
			{"year", "string", ""},
			{"month", "string", ""},
			{"day", "string", ""},
		},
	})
	fmt.Println(res, err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ENDPOINT_COLUMN        = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/column?user.name=%v`
	ENDPOINT_COLUMN_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/column/%v?user.name=%v`
)
View Source
var (
	ENDPOINT_DATABASE        = `%v:%v/templeton/v1/ddl/database?user.name=%v`
	ENDPOINT_DATABASE_DETAIL = `%v:%v/templeton/v1/ddl/database/%v?user.name=%v`
)
View Source
var (
	HTTP_GET    = "GET"
	HTTP_POST   = "POST"
	HTTP_PUT    = "PUT"
	HTTP_DELETE = "DELETE"
)
View Source
var (
	ENDPOINT_PARTITION        = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/partition?user.name=%v`
	ENDPOINT_PARTITION_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/partition/%v?user.name=%v`
)
View Source
var (
	ENDPOINT_PROPERTY        = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/property?user.name=%v`
	ENDPOINT_PROPERTY_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/:%v/property/%v?user.name=%v`
)
View Source
var (
	ENDPOINT_TABLE        = `%v:%v/templeton/v1/ddl/database/%v/table?user.name=%v`
	ENDPOINT_TABLE_DETAIL = `%v:%v/templeton/v1/ddl/database/%v/table/%v?user.name=%v`
	ENDPOINT_TABLE_COPY   = `%v:%v/templeton/v1/ddl/database/%v/table/%v/like/%v?user.name=%v`
)
View Source
var (
	ENDPOINT_EXEC = `%v:%v/templeton/v1/ddl?user.name=%v`
)
View Source
var (
	ENDPOINT_STATUS = `%v:%v/templeton/v1/status?user.name=%v`
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseUrl string
	Port    string
	User    string
	Timeout time.Duration
}

func New

func New(baseurl, port, user string) *Client

func (*Client) CopyTable

func (this *Client) CopyTable(database, existingTable, newTable string) (*CopyTableResponse, error)

func (*Client) CreateColumn

func (this *Client) CreateColumn(database, table, column string) (*CreateColumnResponse, error)

func (*Client) CreateDatabase

func (this *Client) CreateDatabase(database string, in *CreateDatabaseInput) (*CreateDatabaseResponse, error)

func (*Client) CreatePartition

func (this *Client) CreatePartition(database, table string, partitions map[string]string) (*CreatePartitionResponse, error)

func (*Client) CreateProperty

func (this *Client) CreateProperty(database, table, property string) (*CreatePropertyResponse, error)

TODO

func (*Client) CreateTable

func (this *Client) CreateTable(database, table string, in *CreateTableInput) (*CreateTableResponse, error)

func (*Client) DeletePartition

func (this *Client) DeletePartition(database, table string, partitions map[string]string) (*DeletePartitionResponse, error)

func (*Client) DropDatabase

func (this *Client) DropDatabase(database string) (*DropDatabaseResponse, error)

func (*Client) DropTable

func (this *Client) DropTable(database, table string) (*DropTableResponse, error)

func (*Client) Exec

func (this *Client) Exec(sql string) (*ExecResponse, error)

func (*Client) ListColumn

func (this *Client) ListColumn(database, table string) (*ListColumnResponse, error)

func (*Client) ListDatabase

func (this *Client) ListDatabase() (*ListDatabaseResponse, error)

func (*Client) ListPartition

func (this *Client) ListPartition(database, table string) (*ListPartitionResponse, error)

func (*Client) ListProperty

func (this *Client) ListProperty(database, table string) (*ListPropertyResponse, error)

func (*Client) ListTable

func (this *Client) ListTable(database string) (*ListTableResponse, error)

func (*Client) RenameTable

func (this *Client) RenameTable(database, table string, in *RenameTableInput) (*RenameTableResponse, error)

func (*Client) ShowColumn

func (this *Client) ShowColumn(database, table, column string) (*ShowColumnResponse, error)

func (*Client) ShowDatabase

func (this *Client) ShowDatabase(database string) (*ShowDatabaseResponse, error)

func (*Client) ShowPartition

func (this *Client) ShowPartition(database, table string) (*ShowPartitionResponse, error)

func (*Client) ShowProperty

func (this *Client) ShowProperty(database, table, property string) (*ShowPropertyResponse, error)

func (*Client) ShowTable

func (this *Client) ShowTable(database, table string) (*ShowTableResponse, error)

func (*Client) Status

func (this *Client) Status() (*StatusResponse, error)

func (*Client) UpdateTable

func (this *Client) UpdateTable(database, table string) (*UpdateTableResponse, error)

TODO: params

type Column

type Column struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Comment string `json:"comment,omitempty"`
}

type CopyTableResponse

type CopyTableResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
}

type CreateColumnResponse

type CreateColumnResponse struct {
	Column   Column `json:"column"`
	Database string `json:"database"`
	Table    string `json:"table"`
}

type CreateDatabaseInput

type CreateDatabaseInput struct {
	Comment    string      `json:"comment,omitempty"`
	Location   string      `json:"location,omitempty"`
	Properties interface{} `json:"properties,omitempty"`
}

type CreateDatabaseResponse

type CreateDatabaseResponse struct {
	Database string `json:"database"`
}

type CreatePartitionResponse

type CreatePartitionResponse struct {
	Database  string `json:"database"`
	Table     string `json:"table"`
	Partition string `json:"partition"`
}

type CreatePropertyResponse

type CreatePropertyResponse struct {
	Property Property `json:"property"`
	Database string   `json:"database"`
	Table    string   `json:"table"`
}

type CreateTableInput

type CreateTableInput struct {
	Comment     string   `json:"comment,omitempty"`
	Columns     []Column `json:"columns,omitempty"`
	PartitionBy []Column `json:"partitionedBy,omitempty"`
	ClusteredBy struct {
		ColumnNames     []string `json:"columnNames"`
		SortedBy        SortedBy `json:"sortedBy"`
		NumberOfBuckets string   `json:"numberOfBuckets"`
	} `json:"clusteredBy"`
	IfNotExists bool        `json:"ifNotExists,omitempty"`
	External    bool        `json:"external,omitempty"`
	Format      interface{} `json:"format,omitempty"`
	Location    string      `json:"location,omitempty"`
}

type CreateTableResponse

type CreateTableResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
}

type DeletePartitionResponse

type DeletePartitionResponse struct {
	Database  string `json:"database"`
	Table     string `json:"table"`
	Partition string `json:"partition"`
}

type DropDatabaseResponse

type DropDatabaseResponse struct {
	Database string `json:"database"`
}

type DropTableResponse

type DropTableResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
}

type ExecResponse

type ExecResponse struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	Exitcode int    `json:"exitcode"`
}

type ListColumnResponse

type ListColumnResponse struct {
	Columns  []Column `json:"columns"`
	Database string   `json:"database"`
	Table    string   `json:"table"`
}

type ListDatabaseResponse

type ListDatabaseResponse struct {
	Databases []string `json:"databases"`
}

type ListPartitionResponse

type ListPartitionResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`

	Partitions []struct {
		Name   string  `json:"name"`
		Values []Value `json:"values"`
	} `json:"Partitions"`
}

type ListPropertyResponse

type ListPropertyResponse struct {
	Properties Property `json:"properties"`
	Database   string   `json:"database"`
	Table      string   `json:"table"`
}

type ListTableResponse

type ListTableResponse struct {
	Database string   `json:"database"`
	Tables   []string `json:"tables"`
}

type Property

type Property interface{}

type RenameTableInput

type RenameTableInput struct {
	Rename string `json:"rename,omitempty"`
}

type RenameTableResponse

type RenameTableResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
}

type RowFormat

type RowFormat struct {
	FieldsTerminatedBy string `json:"fieldsTerminatedBy"`
}

type ShowColumnResponse

type ShowColumnResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
	Column   Column `json:"column"`
}

type ShowDatabaseResponse

type ShowDatabaseResponse struct {
	Location string `json:"location"`
	Params   string `json:"params"`
	Comment  string `json:"comment"`
	Database string `json:"database"`
}

type ShowPartitionResponse

type ShowPartitionResponse struct {
	Database  string   `json:"database"`
	Table     string   `json:"table"`
	Partition string   `json:"partition"`
	Columns   []Column `json:"columns"`

	// extend
	Partitioned      bool     `json:"partitioned"`
	Location         string   `json:"location"`
	OutputFormat     string   `json:"outputFormat"`
	Owner            string   `json:"owner"`
	PartitionColumns []Column `json:"partitionColumns"`
	InputFormat      string   `json:"inputFormat"`
}

type ShowPropertyResponse

type ShowPropertyResponse struct {
	Database string   `json:"database"`
	Table    string   `json:"table"`
	Property Property `json:"property"`
}

type ShowTableResponse

type ShowTableResponse struct {
	Columns  []Column `json:"columns"`
	Database string   `json:"database"`
	Table    string   `json:"table"`

	// extend
	Partitioned      bool     `json:"partitioned"`
	Location         string   `json:"location"`
	OutputFormat     string   `json:"outputFormat"`
	Owner            string   `json:"owner"`
	PartitionColumns []Column `json:"partitionColumns"`
	InputFormat      string   `json:"inputFormat"`
}

type SortedBy

type SortedBy []struct {
	ColumnName string `json:"columnName"`
	Order      string `json:"order"`
}

type StatusResponse

type StatusResponse struct {
	Status  string `json:"status"`
	Version string `json:"version"`
}

type UpdateTableResponse

type UpdateTableResponse struct {
	Database string `json:"database"`
	Table    string `json:"table"`
}

type Value

type Value struct {
	ColumnName  string `json:"columnName"`
	ColumnValue string `json:"columnValue"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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