Skip to content

Commit

Permalink
Improve schema evolution record test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Apr 26, 2024
1 parent c68f5aa commit ab6f5e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
11 changes: 11 additions & 0 deletions pkg/acceptance/helpers/stage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ func (c *StageClient) PutOnStageWithContent(t *testing.T, id sdk.SchemaObjectIde
require.NoError(t, err)
})
}

func (c *StageClient) CopyIntoTableFromFile(t *testing.T, table, stage sdk.SchemaObjectIdentifier, filename string) {
t.Helper()
ctx := context.Background()

_, err := c.context.client.ExecForTests(ctx, fmt.Sprintf(`COPY INTO %s
FROM @%s/%s
FILE_FORMAT = (type=json)
MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE`, table.FullyQualifiedName(), stage.FullyQualifiedName(), filename))
require.NoError(t, err)
}
34 changes: 9 additions & 25 deletions pkg/sdk/testint/tables_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -1015,24 +1014,6 @@ func TestInt_TablesShowByID(t *testing.T) {
t.Cleanup(cleanupTableHandle(id))
}

uploadFile := func(t *testing.T, stage *sdk.Stage) string {
t.Helper()
f, err := os.CreateTemp("/tmp", "sf_test")
require.NoError(t, err)
w := bufio.NewWriter(f)
_, err = w.WriteString(`{"c1": 1, "c2": "42"}`)
require.NoError(t, err)
err = w.Flush()
require.NoError(t, err)
// disable auto compress to prevent changing file name
_, err = client.ExecForTests(ctx, fmt.Sprintf("PUT file://%s @%s AUTO_COMPRESS=FALSE", f.Name(), stage.ID().FullyQualifiedName()))
name := f.Name()
require.NoError(t, err)
err = os.Remove(f.Name())
require.NoError(t, err)
return filepath.Base(name)
}

t.Run("show by id - same name in different schemas", func(t *testing.T) {
schema, schemaCleanup := testClientHelper().Schema.CreateSchema(t)
t.Cleanup(schemaCleanup)
Expand Down Expand Up @@ -1076,16 +1057,19 @@ func TestInt_TablesShowByID(t *testing.T) {

stage, stageCleanup := testClientHelper().Stage.CreateStageInSchema(t, sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schemaTest.Name))
t.Cleanup(stageCleanup)
filename := uploadFile(t, stage)

_, err = client.QueryUnsafe(ctx, fmt.Sprintf(`COPY INTO %s
FROM @%s/%s
FILE_FORMAT = (type=json)
MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE`, table.ID().FullyQualifiedName(), stage.ID().FullyQualifiedName(), filename))
require.NoError(t, err)
testClientHelper().Stage.PutOnStage(t, stage.ID(), "schema_evolution_record.json")

testClientHelper().Stage.CopyIntoTableFromFile(t, table.ID(), stage.ID(), "schema_evolution_record.json")

currentColumns := testClientHelper().Table.GetTableColumnsFor(t, table.ID())
require.Len(t, currentColumns, 2)
assert.NotEmpty(t, currentColumns[1].SchemaEvolutionRecord)

descColumns, err := client.Tables.DescribeColumns(ctx, sdk.NewDescribeTableColumnsRequest(id))
require.NoError(t, err)
require.Len(t, descColumns, 2)
fmt.Println(*descColumns[1].SchemaEvolutionRecord)
assert.NotEmpty(t, descColumns[1].SchemaEvolutionRecord)
})
}
1 change: 1 addition & 0 deletions pkg/sdk/testint/testdata/schema_evolution_record.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"c1": 1, "c2": "42"}

0 comments on commit ab6f5e3

Please sign in to comment.