wolfeidau commented on code in PR #51:
URL: https://github.com/apache/iceberg-go/pull/51#discussion_r1465798254


##########
catalog/glue.go:
##########
@@ -0,0 +1,168 @@
+// 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 catalog
+
+import (
+       "context"
+       "errors"
+       "fmt"
+
+       "github.com/apache/iceberg-go/io"
+       "github.com/apache/iceberg-go/table"
+       "github.com/aws/aws-sdk-go-v2/aws"
+       "github.com/aws/aws-sdk-go-v2/service/glue"
+       "github.com/aws/aws-sdk-go-v2/service/glue/types"
+)
+
+var (
+       _ Catalog = (*GlueCatalog)(nil)
+)
+
+type glueAPI interface {
+       GetTable(ctx context.Context, params *glue.GetTableInput, optFns 
...func(*glue.Options)) (*glue.GetTableOutput, error)
+       GetTables(ctx context.Context, params *glue.GetTablesInput, optFns 
...func(*glue.Options)) (*glue.GetTablesOutput, error)
+}
+
+type GlueCatalog struct {
+       glueSvc glueAPI
+}
+
+func NewGlueCatalog(opts ...CatalogOption) *GlueCatalog {
+       options := &CatalogOptions{}
+
+       for _, o := range opts {
+               o(options)
+       }
+
+       return &GlueCatalog{
+               glueSvc: glue.NewFromConfig(options.awsConfig),
+       }
+}
+
+// ListTables returns a list of iceberg tables in the given Glue database.
+//
+// The namespace should just contain the Glue database name.
+func (c *GlueCatalog) ListTables(ctx context.Context, namespace 
table.Identifier) ([]table.Identifier, error) {
+       database, err := identifierToGlueDatabase(namespace)
+       if err != nil {
+               return nil, err
+       }
+
+       params := &glue.GetTablesInput{DatabaseName: aws.String(database)}
+
+       tblsRes, err := c.glueSvc.GetTables(ctx, params)
+       if err != nil {
+               return nil, fmt.Errorf("failed to list tables in namespace %s: 
%w", database, err)
+       }
+
+       var icebergTables []table.Identifier
+
+       for _, tbl := range tblsRes.TableList {
+               // skip non iceberg tables
+               // TODO: consider what this would look like for non ICEBERG 
tables as you can convert them to ICEBERG tables via the Glue catalog API.
+               if tbl.Parameters["table_type"] != "ICEBERG" {
+                       continue
+               }
+
+               icebergTables = append(icebergTables,
+                       GlueTableIdentifier(database, aws.ToString(tbl.Name)),
+               )
+       }
+
+       return icebergTables, nil
+}
+
+// LoadTable loads a table from the catalog table details.
+//
+// The identifier should contain the Glue database name, then glue table name.
+func (c *GlueCatalog) LoadTable(ctx context.Context, identifier 
table.Identifier) (*table.Table, error) {
+       database, tableName, err := identifierToGlueTable(identifier)
+       if err != nil {
+               return nil, err
+       }
+
+       location, err := c.getTable(ctx, database, tableName)
+       if err != nil {
+               return nil, err
+       }
+
+       // TODO: consider providing a way to directly access the S3 iofs to 
enable testing of the catalog.
+       iofs, err := io.LoadFS(map[string]string{}, location)

Review Comment:
   @zeroshade apologies, this is fixed, should have passed it in in the first 
place 😅 



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to