gometastore

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

GO Hive Metastore Client

This is an adjusted version of the Hive metastore client library for Golang

Installation

Standard go get:

$ go get github.com/jahnestacado/gometastore

Example usage:

import	(
    "log"
    "github.com/jahnestacado/gometastore"
    "time"
)

func printDatabases(accessToken string, connectionTimeout time.Duration) {
    options = gometastore.Options{AuthToken: accessToken, ConnectTimeout: &connectionTimeout}
    client, err := gometastore.Open("localhost", 9083, &options)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()
    databases, err := client.GetAllDatabases(context.Background())
    if err != nil {
        log.Fatal(err)
    }
    for _, d := range databases {
        fmt.Println(d)
    }
}

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/jahnestacado/gometastore"
)

func main() {
	client, err := gometastore.Open("localhost", 9083, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(client.GetAllDatabases(context.Background()))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakePartition

func MakePartition(table *hive_metastore.Table,
	values []string, parameters map[string]string,
	location string) (*hive_metastore.Partition, error)

MakePartition creates Partition object from ordered list of partition values. Only string values are currently supported. Parameters:

table  - Hive table for which partition is added
values - List of partition values which should match partition schema

Types

type Database

type Database struct {
	Name        string                       `json:"name"`
	Description string                       `json:"description,omitempty"`
	Owner       string                       `json:"owner,omitempty"`
	OwnerType   hive_metastore.PrincipalType `json:"ownerType,omitempty"`
	Location    string                       `json:"location"`
	Parameters  map[string]string            `json:"parameters,omitempty"`
}

Database is a container of other objects in Hive.

type MetastoreClient

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

MetastoreClient represents client handle.

func Open

func Open(host string, port int, options *Options) (*MetastoreClient, error)

Open connection to metastore and return client handle.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/jahnestacado/gometastore"
)

func main() {
	client, err := gometastore.Open("localhost", 9083, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(client.GetAllDatabases(context.Background()))
}
Output:

func (*MetastoreClient) AddPartition

AddPartition adds partition to Hive table.

func (*MetastoreClient) AddPartitions

func (c *MetastoreClient) AddPartitions(ctx context.Context, newParts []*hive_metastore.Partition) error

AddPartitions adds multipe partitions in a single call.

func (*MetastoreClient) AlterTable

func (c *MetastoreClient) AlterTable(ctx context.Context, dbName string, tableName string,
	table *hive_metastore.Table) error

AlterTable modifies existing table with data from the new table

func (*MetastoreClient) Clone

func (c *MetastoreClient) Clone() (client *MetastoreClient, err error)

Clone metastore client and return a new client with its own connection to metastore.

func (*MetastoreClient) Close

func (c *MetastoreClient) Close()

Close connection to metastore. Handle can't be used once it is closed.

func (*MetastoreClient) CreateDatabase

func (c *MetastoreClient) CreateDatabase(ctx context.Context, db *Database) error

CreateDatabase creates database with the specified name, description, parameters and owner.

func (*MetastoreClient) CreateTable

func (c *MetastoreClient) CreateTable(ctx context.Context, table *hive_metastore.Table) error

CreateTable Creates HMS table

func (*MetastoreClient) DropDatabase

func (c *MetastoreClient) DropDatabase(ctx context.Context, dbName string, deleteData bool, cascade bool) error

DropDatabases removes the database specified by name Parameters:

dbName     - database name
deleteData - if true, delete data as well
cascade    - delete everything under the db if true

func (*MetastoreClient) DropPartition

func (c *MetastoreClient) DropPartition(ctx context.Context, dbName string,
	tableName string, values []string, dropData bool) (bool, error)

DropPartition drops partition specified by values.

func (*MetastoreClient) DropPartitionByName

func (c *MetastoreClient) DropPartitionByName(ctx context.Context, dbName string,
	tableName string, partName string, dropData bool) (bool, error)

DropPartitionByName drops partition specified by name.

func (*MetastoreClient) DropPartitions

func (c *MetastoreClient) DropPartitions(ctx context.Context, dbName string,
	tableName string, partNames []string) error

DropPartitions drops multiple partitions within a single table. Partitions are specified by names.

func (*MetastoreClient) DropTable

func (c *MetastoreClient) DropTable(ctx context.Context, dbName string, tableName string, deleteData bool) error

DropTable drops table. Parameters

dbName     - Database name
tableName  - Table name
deleteData - if True, delete data as well

func (*MetastoreClient) GetAllDatabases

func (c *MetastoreClient) GetAllDatabases(ctx context.Context) ([]string, error)

GetAllDatabases returns list of all Hive databases.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/jahnestacado/gometastore"
)

func main() {
	client, err := gometastore.Open("localhost", 9083, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()
	fmt.Println(client.GetAllDatabases(context.Background()))
}
Output:

func (*MetastoreClient) GetAllTables

func (c *MetastoreClient) GetAllTables(ctx context.Context, dbName string) ([]string, error)

GetAllTables returns list of all table names for a given database

func (*MetastoreClient) GetCurrentNotificationId

func (c *MetastoreClient) GetCurrentNotificationId(ctx context.Context) (int64, error)

GetCurrentNotificationId returns value of last notification ID

func (*MetastoreClient) GetDatabase

func (c *MetastoreClient) GetDatabase(ctx context.Context, dbName string) (*Database, error)

GetDatabase returns detailed information about specified Hive database.

func (*MetastoreClient) GetDatabases

func (c *MetastoreClient) GetDatabases(ctx context.Context, pattern string) ([]string, error)

GetDatabases returns list of all databases matching pattern. The pattern is interpreted by HMS.

func (*MetastoreClient) GetNextNotification

func (c *MetastoreClient) GetNextNotification(ctx context.Context, lastEvent int64,
	maxEvents int32) ([]*hive_metastore.NotificationEvent, error)

GetNextNotification returns next available notification.

func (*MetastoreClient) GetPartitionByName

func (c *MetastoreClient) GetPartitionByName(ctx context.Context, dbName string, tableName string,
	partName string) (*hive_metastore.Partition, error)

GetPartitionByName returns Partition for the given partition name.

func (*MetastoreClient) GetPartitionNames

func (c *MetastoreClient) GetPartitionNames(ctx context.Context, dbName string, tableName string, max int) ([]string, error)

GetPartitionNames returns list of partition names for a table.

func (*MetastoreClient) GetPartitions

func (c *MetastoreClient) GetPartitions(ctx context.Context, dbName string, tableName string,
	maxCount int) ([]*hive_metastore.Partition, error)

GetPartitions returns all (or up to maxCount partitions of a table.

func (*MetastoreClient) GetPartitionsByNames

func (c *MetastoreClient) GetPartitionsByNames(ctx context.Context, dbName string, tableName string,
	partNames []string) ([]*hive_metastore.Partition, error)

GetPartitionsByNames returns multiple partitions specified by names.

func (*MetastoreClient) GetTable

func (c *MetastoreClient) GetTable(ctx context.Context, dbName string, tableName string) (*hive_metastore.Table, error)

GetTable returns detailed information about the specified table

func (*MetastoreClient) GetTableMeta

func (c *MetastoreClient) GetTableMeta(ctx context.Context, db string,
	table string, tableTypes []string) ([]*hive_metastore.TableMeta, error)

GetTableMeta returns list of tables matching specified search criteria. Parameters:

db - database name pattern
table - table name pattern
tableTypes - list of Table types - should be either TABLE or VIEW

func (*MetastoreClient) GetTableObjects

func (c *MetastoreClient) GetTableObjects(ctx context.Context, dbName string, tableNames []string) ([]*hive_metastore.Table, error)

GetTableObjects returns list of Table objects for the given database and list of table names.

func (*MetastoreClient) GetTables

func (c *MetastoreClient) GetTables(ctx context.Context, dbName string, pattern string) ([]string, error)

GetTables returns list of tables matching given pattern for the given database. Matching is performed on the server side.

func (*MetastoreClient) GetTablesByType

func (c *MetastoreClient) GetTablesByType(ctx context.Context, dbName string,
	table string, tableType string) ([]string, error)

GetTablesByType returns list of tables matching specified search criteria. Parameters:

dbName - database name
table - table name pattern
tableType - Table type - should be either TABLE or VIEW

type Options

type Options struct {
	AuthToken      string
	ConnectTimeout *time.Duration
}

type PartitionBuilder

type PartitionBuilder struct {
	Table      *hive_metastore.Table
	Parameters map[string]string
	Values     []string
	Location   string
}

func NewPartitionBuilder

func NewPartitionBuilder(table *hive_metastore.Table, values []string) (*PartitionBuilder, error)

func (*PartitionBuilder) Build

func (*PartitionBuilder) WithLocation

func (pb *PartitionBuilder) WithLocation(location string) *PartitionBuilder

func (*PartitionBuilder) WithParameter

func (pb *PartitionBuilder) WithParameter(key string, value string) *PartitionBuilder

func (*PartitionBuilder) WithParameters

func (pb *PartitionBuilder) WithParameters(parameters map[string]string) *PartitionBuilder

type TableBuilder

type TableBuilder struct {
	Db            string
	Name          string
	Type          TableType
	Serde         string
	Owner         string
	InputFormat   string
	OutputFormat  string
	Location      string
	Columns       []hive_metastore.FieldSchema
	PartitionKeys []hive_metastore.FieldSchema
	Parameters    map[string]string
}

TableBuilder provides builder pattern for table objects

func NewTableBuilder

func NewTableBuilder(db string, tableName string) *TableBuilder

func (*TableBuilder) AsExternal

func (tb *TableBuilder) AsExternal() *TableBuilder

Mark table as external

func (*TableBuilder) Build

func (tb *TableBuilder) Build() *hive_metastore.Table

Build HMS Table object.

func (*TableBuilder) WithColumns

func (tb *TableBuilder) WithColumns(columns []hive_metastore.FieldSchema) *TableBuilder

WithColumns specifies table columns

func (*TableBuilder) WithInputFormat

func (tb *TableBuilder) WithInputFormat(format string) *TableBuilder

WithInputFormat specifies table input format

func (*TableBuilder) WithLocation

func (tb *TableBuilder) WithLocation(location string) *TableBuilder

WithLocation specifies table location

func (*TableBuilder) WithOutputFormat

func (tb *TableBuilder) WithOutputFormat(format string) *TableBuilder

WithOutputFormat specifies table output format

func (*TableBuilder) WithOwner

func (tb *TableBuilder) WithOwner(owner string) *TableBuilder

WithOwner specifies table owner

func (*TableBuilder) WithParameter

func (tb *TableBuilder) WithParameter(name string, value string) *TableBuilder

WithParameter adds table parameter

func (*TableBuilder) WithParameters

func (tb *TableBuilder) WithParameters(parameters map[string]string) *TableBuilder

WithParameters specifies table parameters

func (*TableBuilder) WithPartitionKeys

func (tb *TableBuilder) WithPartitionKeys(partKeys []hive_metastore.FieldSchema) *TableBuilder

WithPartitionKeys specifies table partition keys

func (*TableBuilder) WithSerde

func (tb *TableBuilder) WithSerde(serde string) *TableBuilder

WithSerde specifies table serde

func (*TableBuilder) WithType

func (tb *TableBuilder) WithType(t TableType) *TableBuilder

WithType specifies table type

type TableType

type TableType int
const (
	TableTypeManaged TableType = iota
	TableTypeExternal
	TableTypeView
	TableTypeIndex
)

func (TableType) String

func (val TableType) String() string

Directories

Path Synopsis
thrift
gen-go/hive_metastore
Package hive_metastore provides raw access to HMS Thrift API.
Package hive_metastore provides raw access to HMS Thrift API.

Jump to

Keyboard shortcuts

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