Skip to content
Closed
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
11 changes: 9 additions & 2 deletions catalog/glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type Catalog struct {
catalogId *string
awsCfg *aws.Config
props iceberg.Properties
fsLoader FSLoaderFunction
}

// NewCatalog creates a new instance of glue.Catalog with the given options.
Expand All @@ -152,11 +153,17 @@ func NewCatalog(opts ...Option) *Catalog {
catalogId = nil
}

fsLoaderFn := io.LoadFS
if glueOps.fsLoaderFn != nil {
fsLoaderFn = glueOps.fsLoaderFn
}

return &Catalog{
glueSvc: glue.NewFromConfig(glueOps.awsConfig),
catalogId: catalogId,
awsCfg: &glueOps.awsConfig,
props: iceberg.Properties(glueOps.awsProperties),
fsLoader: fsLoaderFn,
}
}

Expand Down Expand Up @@ -220,7 +227,7 @@ func (c *Catalog) LoadTable(ctx context.Context, identifier table.Identifier, pr

ctx = utils.WithAwsConfig(ctx, c.awsCfg)
// TODO: consider providing a way to directly access the S3 iofs to enable testing of the catalog.
iofs, err := io.LoadFS(ctx, props, location)
iofs, err := c.fsLoader(ctx, props, location)
if err != nil {
return nil, fmt.Errorf("failed to load table %s.%s: %w", database, tableName, err)
}
Expand Down Expand Up @@ -313,7 +320,7 @@ func (c *Catalog) RegisterTable(ctx context.Context, identifier table.Identifier
}
// Load the metadata file to get table properties
ctx = utils.WithAwsConfig(ctx, c.awsCfg)
iofs, err := io.LoadFS(ctx, nil, metadataLocation)
iofs, err := c.fsLoader(ctx, nil, metadataLocation)
if err != nil {
return nil, fmt.Errorf("failed to load metadata file at %s: %w", metadataLocation, err)
}
Expand Down
12 changes: 12 additions & 0 deletions catalog/glue/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package glue

import (
"context"

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

type AwsProperties map[string]string

type Option func(*options)

type FSLoaderFunction func(ctx context.Context, props map[string]string, location string) (io.IO, error)
Copy link
Member

Choose a reason for hiding this comment

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

Rather than doing this, would it make more sense to set up a registry with the io.IO similar to the catalog registry we have? Where the scheme can be used to register specific handlers for file systems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zeroshade thanks for the feedback. Maybe #455 looks like what you had in mind?


// WithAwsConfig sets the AWS configuration for the catalog.
func WithAwsConfig(cfg aws.Config) Option {
return func(o *options) {
Expand All @@ -38,7 +43,14 @@ func WithAwsProperties(props AwsProperties) Option {
}
}

func WithFSLoaderFunction(fsLoaderFn FSLoaderFunction) Option {
return func(o *options) {
o.fsLoaderFn = fsLoaderFn
}
}

type options struct {
awsConfig aws.Config
awsProperties AwsProperties
fsLoaderFn FSLoaderFunction
}
Loading