Skip to content

Commit

Permalink
fix: reading file formats with no default schema (#1936)
Browse files Browse the repository at this point in the history
* Add failing test covering searching for file format in different schema.

* Use IN SCHEMA in fileformat's ShowById.
  • Loading branch information
sfc-gh-ngaberel committed Jul 7, 2023
1 parent 6d252fa commit c5602f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/sdk/file_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ func (v *fileFormats) ShowByID(ctx context.Context, id SchemaObjectIdentifier) (
Like: &Like{
Pattern: String(id.Name()),
},
In: &In{
Schema: NewSchemaIdentifier(id.databaseName, id.schemaName),
},
})
if err != nil {
return nil, err
Expand Down
30 changes: 30 additions & 0 deletions pkg/sdk/file_format_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,33 @@ func TestInt_FileFormatsShow(t *testing.T) {
assert.Contains(t, fileFormats, fileFormatTest2)
})
}

func TestInt_FileFormatsShowById(t *testing.T) {
client := testClient(t)
ctx := context.Background()

databaseTest, cleanupDatabase := createDatabase(t, client)
t.Cleanup(cleanupDatabase)
schemaTest, cleanupSchema := createSchema(t, client, databaseTest)
t.Cleanup(cleanupSchema)
fileFormatTest, cleanupFileFormat := createFileFormat(t, client, schemaTest.ID())
t.Cleanup(cleanupFileFormat)

databaseTest2, cleanupDatabase2 := createDatabase(t, client)
t.Cleanup(cleanupDatabase2)
schemaTest2, cleanupSchema2 := createSchema(t, client, databaseTest2)
t.Cleanup(cleanupSchema2)

t.Run("show format in different schema", func(t *testing.T) {
err := client.Sessions.UseDatabase(ctx, databaseTest2.ID())
require.NoError(t, err)
err = client.Sessions.UseSchema(ctx, schemaTest2.ID())
require.NoError(t, err)

fileFormat, err := client.FileFormats.ShowByID(ctx, fileFormatTest.ID())
require.NoError(t, err)
assert.Equal(t, databaseTest.Name, fileFormat.Name.databaseName)
assert.Equal(t, schemaTest.Name, fileFormat.Name.schemaName)
assert.Equal(t, fileFormatTest.Name.name, fileFormat.Name.name)
})
}
8 changes: 6 additions & 2 deletions pkg/sdk/file_format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,18 @@ func TestFileFormatsShow(t *testing.T) {

func TestFileFormatsShowById(t *testing.T) {
t.Run("simple", func(t *testing.T) {
id := NewSchemaObjectIdentifier("db", "schema", "ff")
opts := &ShowFileFormatsOptions{
Like: &Like{
Pattern: String(NewSchemaObjectIdentifier("db", "schema", "ff").Name()),
Pattern: String(id.Name()),
},
In: &In{
Schema: NewSchemaIdentifier(id.databaseName, id.schemaName),
},
}
actual, err := structToSQL(opts)
require.NoError(t, err)
expected := `SHOW FILE FORMATS LIKE 'ff'`
expected := `SHOW FILE FORMATS LIKE 'ff' IN SCHEMA "db"."schema"`
assert.Equal(t, expected, actual)
})
}
Expand Down

0 comments on commit c5602f5

Please sign in to comment.