Skip to content

Commit

Permalink
[snowflake] Use UppercaseEscNames: true for tests (redux)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed May 1, 2024
1 parent 55eb549 commit 94d0b00
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
5 changes: 3 additions & 2 deletions lib/destination/ddl/ddl_alter_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ddl_test

import (
"fmt"
"strings"
"time"

"github.com/artie-labs/transfer/lib/config"
Expand Down Expand Up @@ -284,7 +285,7 @@ func (d *DDLTestSuite) TestAlterDelete_Complete() {
ContainOtherOperations: true,
ColumnOp: constants.Delete,
CdcTime: ts.Add(2 * constants.DeletionConfidencePadding),
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
Mode: config.Replication,
}

Expand Down Expand Up @@ -339,7 +340,7 @@ func (d *DDLTestSuite) TestAlterDelete_Complete() {
execQuery, _ := d.fakeSnowflakeStagesStore.ExecArgsForCall(0)
var found bool
for key := range allColsMap {
if execQuery == fmt.Sprintf("ALTER TABLE %s drop COLUMN %s", snowflakeName, key) {
if execQuery == fmt.Sprintf(`ALTER TABLE %s drop COLUMN "%s"`, snowflakeName, strings.ToUpper(key)) {
found = true
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/destination/ddl/ddl_create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *DDLTestSuite) Test_CreateTable() {
_dwh: d.snowflakeStagesStore,
_tableConfig: snowflakeStagesTc,
_fakeStore: d.fakeSnowflakeStagesStore,
_expectedQuery: fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (name string)", snowflakeTableID.FullyQualifiedName()),
_expectedQuery: fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ("NAME" string)`, snowflakeTableID.FullyQualifiedName()),
},
} {
alterTableArgs := ddl.AlterTableArgs{
Expand All @@ -61,7 +61,7 @@ func (d *DDLTestSuite) Test_CreateTable() {
TableID: dwhTc._tableID,
CreateTable: dwhTc._tableConfig.CreateTable(),
ColumnOp: constants.Add,
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true), // Will be ignored by BigQuery
Mode: config.Replication,
}

Expand Down Expand Up @@ -102,17 +102,17 @@ func (d *DDLTestSuite) TestCreateTable() {
{
name: "happy path",
cols: happyPathCols,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" (user_id string)`,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" ("USER_ID" string)`,
},
{
name: "happy path + enabled",
cols: twoCols,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" (user_id string,enabled boolean)`,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" ("USER_ID" string,"ENABLED" boolean)`,
},
{
name: "complex table creation",
cols: bunchOfCols,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" (user_id string,enabled_boolean boolean,array array,struct variant)`,
expectedQuery: `CREATE TABLE IF NOT EXISTS demo.public."EXPERIMENTS" ("USER_ID" string,"ENABLED_BOOLEAN" boolean,"ARRAY" array,"STRUCT" variant)`,
},
}

Expand All @@ -128,7 +128,7 @@ func (d *DDLTestSuite) TestCreateTable() {
CreateTable: tc.CreateTable(),
ColumnOp: constants.Add,
CdcTime: time.Now().UTC(),
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
Mode: config.Replication,
}

Expand Down
17 changes: 11 additions & 6 deletions lib/destination/ddl/ddl_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ type DDLTestSuite struct {
}

func (d *DDLTestSuite) SetupTest() {
cfg := config.Config{
Redshift: &config.Redshift{},
}

d.bigQueryCfg = config.Config{
BigQuery: &config.BigQuery{
ProjectID: "artie-project",
Expand All @@ -48,12 +44,21 @@ func (d *DDLTestSuite) SetupTest() {

d.fakeSnowflakeStagesStore = &mocks.FakeStore{}
snowflakeStagesStore := db.Store(d.fakeSnowflakeStagesStore)
d.snowflakeStagesStore, err = snowflake.LoadSnowflake(cfg, &snowflakeStagesStore)
snowflakeCfg := config.Config{
Snowflake: &config.Snowflake{},
SharedDestinationConfig: config.SharedDestinationConfig{
UppercaseEscapedNames: true,
},
}
d.snowflakeStagesStore, err = snowflake.LoadSnowflake(snowflakeCfg, &snowflakeStagesStore)
assert.NoError(d.T(), err)

d.fakeRedshiftStore = &mocks.FakeStore{}
redshiftStore := db.Store(d.fakeRedshiftStore)
d.redshiftStore, err = redshift.LoadRedshift(cfg, &redshiftStore)
redshiftCfg := config.Config{
Redshift: &config.Redshift{},
}
d.redshiftStore, err = redshift.LoadRedshift(redshiftCfg, &redshiftStore)
assert.NoError(d.T(), err)
}

Expand Down
10 changes: 5 additions & 5 deletions lib/destination/dml/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMergeStatementSoftDelete(t *testing.T) {
TableID: MockTableIdentifier{fqTable},
SubQuery: subQuery,
IdempotentKey: idempotentKey,
PrimaryKeys: []columns.Wrapper{columns.NewWrapper(columns.NewColumn("id", typing.Invalid), false, constants.Snowflake)},
PrimaryKeys: []columns.Wrapper{columns.NewWrapper(columns.NewColumn("id", typing.Invalid), true, constants.Snowflake)},
Columns: &_cols,
DestKind: constants.Snowflake,
Dialect: sql.SnowflakeDialect{UppercaseEscNames: true},
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestMergeStatementIdempotentKey(t *testing.T) {
TableID: MockTableIdentifier{fqTable},
SubQuery: subQuery,
IdempotentKey: "updated_at",
PrimaryKeys: []columns.Wrapper{columns.NewWrapper(columns.NewColumn("id", typing.Invalid), false, constants.Snowflake)},
PrimaryKeys: []columns.Wrapper{columns.NewWrapper(columns.NewColumn("id", typing.Invalid), true, constants.Snowflake)},
Columns: &_cols,
DestKind: constants.Snowflake,
Dialect: sql.SnowflakeDialect{UppercaseEscNames: true},
Expand Down Expand Up @@ -205,8 +205,8 @@ func TestMergeStatementCompositeKey(t *testing.T) {
SubQuery: subQuery,
IdempotentKey: "updated_at",
PrimaryKeys: []columns.Wrapper{
columns.NewWrapper(columns.NewColumn("id", typing.Invalid), false, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("another_id", typing.Invalid), false, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("id", typing.Invalid), true, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("another_id", typing.Invalid), true, constants.Snowflake),
},
Columns: &_cols,
DestKind: constants.Snowflake,
Expand All @@ -219,7 +219,7 @@ func TestMergeStatementCompositeKey(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, mergeSQL, fmt.Sprintf("MERGE INTO %s", fqTable), mergeSQL)
assert.Contains(t, mergeSQL, fmt.Sprintf("cc.%s >= c.%s", "updated_at", "updated_at"), fmt.Sprintf("Idempotency key: %s", mergeSQL))
assert.Contains(t, mergeSQL, "cc ON c.id = cc.id and c.another_id = cc.another_id", mergeSQL)
assert.Contains(t, mergeSQL, `cc ON c."ID" = cc."ID" and c."ANOTHER_ID" = cc."ANOTHER_ID"`, mergeSQL)
}

func TestMergeStatementEscapePrimaryKeys(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/destination/dml/merge_valid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestMergeArgument_Valid(t *testing.T) {
primaryKeys := []columns.Wrapper{
columns.NewWrapper(columns.NewColumn("id", typing.Integer), false, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("id", typing.Integer), true, constants.Snowflake),
}

var cols columns.Columns
Expand Down
4 changes: 2 additions & 2 deletions lib/typing/columns/columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func TestColumnsUpdateQuery(t *testing.T) {
name: "string and toast",
columns: stringAndToastCols,
destKind: constants.Snowflake,
expectedString: "foo= CASE WHEN COALESCE(cc.foo != '__debezium_unavailable_value', true) THEN cc.foo ELSE c.foo END,bar=cc.bar",
expectedString: `"FOO"= CASE WHEN COALESCE(cc."FOO" != '__debezium_unavailable_value', true) THEN cc."FOO" ELSE c."FOO" END,"BAR"=cc."BAR"`,
},
{
name: "struct, string and toast string",
Expand Down Expand Up @@ -519,7 +519,7 @@ func TestColumnsUpdateQuery(t *testing.T) {
}

for _, _testCase := range testCases {
actualQuery := _testCase.columns.UpdateQuery(_testCase.destKind, false, _testCase.skipDeleteCol)
actualQuery := _testCase.columns.UpdateQuery(_testCase.destKind, _testCase.destKind == constants.Snowflake, _testCase.skipDeleteCol)
assert.Equal(t, _testCase.expectedString, actualQuery, _testCase.name)
}
}

0 comments on commit 94d0b00

Please sign in to comment.