-
Notifications
You must be signed in to change notification settings - Fork 141
Initial support for Hive Catalog. #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
87a56ba
91dbdd5
51b1dda
c298aa1
8f56ae7
d85f65d
c3e50aa
5e9a1ed
51701f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
| Close() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not using an |
||
|
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading gohive correctly, this requires the |
||
| } | ||
|
|
||
| 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() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we set |
||
| } | ||
| } | ||
|
|
||
| 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, | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
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?