Skip to content

Commit

Permalink
Fix wrong pattern matching in SHOW WAREHOUSES.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ngaberel committed May 12, 2023
1 parent 9024050 commit 954051e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/resources/warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,11 @@ func ReadWarehouse(d *schema.ResourceData, meta interface{}) error {

id := helpers.DecodeSnowflakeID(d.Id()).(sdk.AccountObjectIdentifier)

warehouses, err := client.Warehouses.Show(ctx, &sdk.WarehouseShowOptions{
Like: &sdk.Like{
Pattern: sdk.String(id.Name()),
},
})
w, err := client.Warehouses.ShowById(ctx, id)
if err != nil {
return err
}

w := warehouses[0]

if err = d.Set("name", w.Name); err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/sdk/warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Warehouses interface {
Drop(ctx context.Context, id AccountObjectIdentifier, opts *WarehouseDropOptions) error
// Show returns a list of warehouses.
Show(ctx context.Context, opts *WarehouseShowOptions) ([]*Warehouse, error)
// Show + filter to return SHOW data for a single warehouse.
ShowById(ctx context.Context, id ObjectIdentifier) (*Warehouse, error)
// Describe returns the details of a warehouse.
Describe(ctx context.Context, id AccountObjectIdentifier) (*WarehouseDetails, error)
}
Expand Down Expand Up @@ -416,6 +418,24 @@ func (c *warehouses) Show(ctx context.Context, opts *WarehouseShowOptions) ([]*W
return resultList, nil
}

func (c *warehouses) ShowById(ctx context.Context, id ObjectIdentifier) (*Warehouse, error) {
results, err := c.Show(ctx, &WarehouseShowOptions{
Like: &Like{
Pattern: String(id.Name()),
},
})
if err != nil {
return nil, err
}

for _, res := range results {
if res.ID().name == id.Name() {
return res, nil
}
}
return nil, ErrObjectNotExistOrAuthorized
}

type warehouseDescribeOptions struct {
describe bool `ddl:"static" db:"DESCRIBE"` //lint:ignore U1000 This is used in the ddl tag
warehouse bool `ddl:"static" db:"WAREHOUSE"` //lint:ignore U1000 This is used in the ddl tag
Expand Down

0 comments on commit 954051e

Please sign in to comment.