zeroshade commented on code in PR #678: URL: https://github.com/apache/iceberg-go/pull/678#discussion_r2722312040
########## catalog/hive/client.go: ########## @@ -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() + + 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 +} + +func NewHiveClient(uri string, opts *HiveOptions) (HiveClient, error) { + 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" Review Comment: 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. ########## catalog/hive/client.go: ########## @@ -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 { Review Comment: is there any particular reason to export this? Is the intent that users should be able to provide their own HiveClient if they want? ########## catalog/hive/client.go: ########## @@ -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() Review Comment: Not using an `io.Closer` where the Close method returns `error`? ########## catalog/hive/client.go: ########## @@ -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() + + 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 +} + +func NewHiveClient(uri string, opts *HiveOptions) (HiveClient, error) { Review Comment: Do we expect users to actually be using this directly as opposed to just using NewCatalog? ########## catalog/hive/client.go: ########## @@ -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() + + 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 Review Comment: Most of the methods here just forward to client, should we just embed the client rather than have it be a member? ########## catalog/hive/client.go: ########## @@ -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() + + 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 +} + +func NewHiveClient(uri string, opts *HiveOptions) (HiveClient, error) { + 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" + } + + 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() Review Comment: Shouldn't we set `c.client = nil` after we close? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
