Skip to content

Commit

Permalink
feat: move to functional options to cleanup creation of catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfeidau committed Jan 22, 2024
1 parent bc30773 commit 6327be2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 14 additions & 0 deletions catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"

"github.com/apache/iceberg-go/table"
"github.com/aws/aws-sdk-go-v2/aws"
)

type CatalogType string
Expand All @@ -39,6 +40,19 @@ var (
ErrNoSuchTable = errors.New("table does not exist")
)

// WithAwsConfig sets the AWS configuration for the catalog.
func WithAwsConfig(cfg aws.Config) CatalogOption {
return func(o *CatalogOptions) {
o.awsConfig = cfg
}
}

type CatalogOption func(*CatalogOptions)

type CatalogOptions struct {
awsConfig aws.Config
}

// Catalog for iceberg table operations like create, drop, load, list and others.
type Catalog interface {
// ListTables returns a list of table identifiers in the catalog, with the returned
Expand Down
10 changes: 8 additions & 2 deletions catalog/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ type GlueCatalog struct {
glueSvc glueAPI
}

func NewGlueCatalog(awscfg aws.Config) *GlueCatalog {
func NewGlueCatalog(opts ...CatalogOption) *GlueCatalog {
options := &CatalogOptions{}

for _, o := range opts {
o(options)
}

return &GlueCatalog{
glueSvc: glue.NewFromConfig(awscfg),
glueSvc: glue.NewFromConfig(options.awsConfig),
}
}

Expand Down
4 changes: 2 additions & 2 deletions catalog/glue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestGlueListTableIntegration(t *testing.T) {
awscfg, err := config.LoadDefaultConfig(context.TODO(), config.WithClientLogMode(aws.LogRequest|aws.LogResponse))
assert.NoError(err)

catalog := NewGlueCatalog(awscfg)
catalog := NewGlueCatalog(WithAwsConfig(awscfg))

tables, err := catalog.ListTables(context.TODO(), GlueDatabaseIdentifier(os.Getenv("TEST_DATABASE_NAME")))
assert.NoError(err)
Expand All @@ -133,7 +133,7 @@ func TestGlueLoadTableIntegration(t *testing.T) {
awscfg, err := config.LoadDefaultConfig(context.TODO(), config.WithClientLogMode(aws.LogRequest|aws.LogResponse))
assert.NoError(err)

catalog := NewGlueCatalog(awscfg)
catalog := NewGlueCatalog(WithAwsConfig(awscfg))

table, err := catalog.LoadTable(context.TODO(), []string{os.Getenv("TEST_DATABASE_NAME"), os.Getenv("TEST_TABLE_NAME")})
assert.NoError(err)
Expand Down

0 comments on commit 6327be2

Please sign in to comment.