Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
go test -tags integration -v -run="^TestScanner" ./table
go test -tags integration -v ./io
go test -tags integration -v -run="^TestRestIntegration$" ./catalog/rest

go test -tags=integration -v ./catalog/hive/...
- name: Run spark integration tests
env:
AWS_S3_ENDPOINT: "${{ env.AWS_S3_ENDPOINT }}"
Expand Down
147 changes: 147 additions & 0 deletions catalog/hive/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package hive

import (
"context"
"fmt"
"net/url"
"strconv"

"github.com/beltran/gohive"
"github.com/beltran/gohive/hive_metastore"
)

type HiveClient interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any particular reason to export this? Is the intent that users should be able to provide their own HiveClient if they want?

Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using an io.Closer where the Close method returns error?


GetDatabase(ctx context.Context, name string) (*hive_metastore.Database, error)
CreateDatabase(ctx context.Context, database *hive_metastore.Database) error
AlterDatabase(ctx context.Context, dbname string, db *hive_metastore.Database) error
DropDatabase(ctx context.Context, name string, deleteData, cascade bool) error
GetAllDatabases(ctx context.Context) ([]string, error)

GetTable(ctx context.Context, dbName, tableName string) (*hive_metastore.Table, error)
CreateTable(ctx context.Context, tbl *hive_metastore.Table) error
AlterTable(ctx context.Context, dbName, tableName string, newTbl *hive_metastore.Table) error
DropTable(ctx context.Context, dbName, tableName string, deleteData bool) error
GetTables(ctx context.Context, dbName, pattern string) ([]string, error)

Lock(ctx context.Context, request *hive_metastore.LockRequest) (*hive_metastore.LockResponse, error)
CheckLock(ctx context.Context, lockId int64) (*hive_metastore.LockResponse, error)
Unlock(ctx context.Context, lockId int64) error
}

type thriftClient struct {
client *gohive.HiveMetastoreClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the methods here just forward to client, should we just embed the client rather than have it be a member?

}

func NewHiveClient(uri string, opts *HiveOptions) (HiveClient, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect users to actually be using this directly as opposed to just using NewCatalog?

parsed, err := url.Parse(uri)
if err != nil {
return nil, fmt.Errorf("invalid URI: %w", err)
}

host := parsed.Hostname()
portStr := parsed.Port()
if portStr == "" {
portStr = "9083"
}
port, err := strconv.Atoi(portStr)
if err != nil {
return nil, fmt.Errorf("invalid port: %w", err)
}

// Determine authentication mode
auth := "NOSASL"
if opts != nil && opts.KerberosAuth {
auth = "KERBEROS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading gohive correctly, this requires the kerberos tag to build correctly, right? Can we instead use one of the pure go implementations that don't rely on cgo? Like gokrb etc.

}

config := gohive.NewMetastoreConnectConfiguration()
config.TransportMode = "binary"

client, err := gohive.ConnectToMetastore(host, port, auth, config)
if err != nil {
return nil, fmt.Errorf("failed to connect to metastore: %w", err)
}

return &thriftClient{client: client}, nil
}

func (c *thriftClient) Close() {
if c.client != nil {
c.client.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we set c.client = nil after we close?

}
}

func (c *thriftClient) GetDatabase(ctx context.Context, name string) (*hive_metastore.Database, error) {
return c.client.Client.GetDatabase(ctx, name)
}

func (c *thriftClient) CreateDatabase(ctx context.Context, database *hive_metastore.Database) error {
return c.client.Client.CreateDatabase(ctx, database)
}

func (c *thriftClient) AlterDatabase(ctx context.Context, dbname string, db *hive_metastore.Database) error {
return c.client.Client.AlterDatabase(ctx, dbname, db)
}

func (c *thriftClient) DropDatabase(ctx context.Context, name string, deleteData, cascade bool) error {
return c.client.Client.DropDatabase(ctx, name, deleteData, cascade)
}

func (c *thriftClient) GetAllDatabases(ctx context.Context) ([]string, error) {
return c.client.Client.GetAllDatabases(ctx)
}

func (c *thriftClient) GetTable(ctx context.Context, dbName, tableName string) (*hive_metastore.Table, error) {
return c.client.Client.GetTable(ctx, dbName, tableName)
}

func (c *thriftClient) CreateTable(ctx context.Context, tbl *hive_metastore.Table) error {
return c.client.Client.CreateTable(ctx, tbl)
}

func (c *thriftClient) AlterTable(ctx context.Context, dbName, tableName string, newTbl *hive_metastore.Table) error {
return c.client.Client.AlterTable(ctx, dbName, tableName, newTbl)
}

func (c *thriftClient) DropTable(ctx context.Context, dbName, tableName string, deleteData bool) error {
return c.client.Client.DropTable(ctx, dbName, tableName, deleteData)
}

func (c *thriftClient) GetTables(ctx context.Context, dbName, pattern string) ([]string, error) {
return c.client.Client.GetTables(ctx, dbName, pattern)
}

func (c *thriftClient) Lock(ctx context.Context, request *hive_metastore.LockRequest) (*hive_metastore.LockResponse, error) {
return c.client.Client.Lock(ctx, request)
}

func (c *thriftClient) CheckLock(ctx context.Context, lockId int64) (*hive_metastore.LockResponse, error) {
return c.client.Client.CheckLock(ctx, &hive_metastore.CheckLockRequest{
Lockid: lockId,
})
}

func (c *thriftClient) Unlock(ctx context.Context, lockId int64) error {
return c.client.Client.Unlock(ctx, &hive_metastore.UnlockRequest{
Lockid: lockId,
})
}
Loading
Loading