Skip to content

Commit

Permalink
fix: update the LoadTable to accept LoadFS props
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfeidau committed Jan 25, 2024
1 parent 6327be2 commit 1aa77dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Catalog interface {
// identifiers containing the information required to load the table via that catalog.
ListTables(ctx context.Context, namespace table.Identifier) ([]table.Identifier, error)
// LoadTable loads a table from the catalog and returns a Table with the metadata.
LoadTable(ctx context.Context, identifier table.Identifier) (*table.Table, error)
LoadTable(ctx context.Context, identifier table.Identifier, props map[string]string) (*table.Table, error)
// CatalogType returns the type of the catalog.
CatalogType() CatalogType
}
8 changes: 6 additions & 2 deletions catalog/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,23 @@ func (c *GlueCatalog) ListTables(ctx context.Context, namespace table.Identifier
// 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) {
func (c *GlueCatalog) LoadTable(ctx context.Context, identifier table.Identifier, props map[string]string) (*table.Table, error) {
database, tableName, err := identifierToGlueTable(identifier)
if err != nil {
return nil, err
}

if props == nil {
props = map[string]string{}
}

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)
iofs, err := io.LoadFS(props, location)
if err != nil {
return nil, fmt.Errorf("failed to load table %s.%s: %w", database, tableName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion catalog/glue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestGlueLoadTableIntegration(t *testing.T) {

catalog := NewGlueCatalog(WithAwsConfig(awscfg))

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

0 comments on commit 1aa77dd

Please sign in to comment.