Skip to content

Commit

Permalink
[snowflake] Use uppercaseEscNames: true for tests (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored Apr 29, 2024
1 parent a8f99c0 commit 6bd7d2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lib/destination/ddl/ddl_temp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d *DDLTestSuite) TestCreateTemporaryTable_Errors() {
TemporaryTable: true,
ColumnOp: constants.Add,
CdcTime: time.Time{},
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
Mode: config.Replication,
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (d *DDLTestSuite) TestCreateTemporaryTable() {
TemporaryTable: true,
ColumnOp: constants.Add,
CdcTime: time.Time{},
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
Mode: config.Replication,
}

Expand All @@ -91,7 +91,7 @@ func (d *DDLTestSuite) TestCreateTemporaryTable() {

assert.Contains(d.T(),
query,
`CREATE TABLE IF NOT EXISTS db.schema."TEMPTABLENAME" (foo string,bar float,"start" string) STAGE_COPY_OPTIONS = ( PURGE = TRUE ) STAGE_FILE_FORMAT = ( TYPE = 'csv' FIELD_DELIMITER= '\t' FIELD_OPTIONALLY_ENCLOSED_BY='"' NULL_IF='\\N' EMPTY_FIELD_AS_NULL=FALSE)`,
`CREATE TABLE IF NOT EXISTS db.schema."TEMPTABLENAME" (foo string,bar float,"START" string) STAGE_COPY_OPTIONS = ( PURGE = TRUE ) STAGE_FILE_FORMAT = ( TYPE = 'csv' FIELD_DELIMITER= '\t' FIELD_OPTIONALLY_ENCLOSED_BY='"' NULL_IF='\\N' EMPTY_FIELD_AS_NULL=FALSE)`,
query)
}
{
Expand Down
16 changes: 8 additions & 8 deletions lib/destination/dml/merge_parts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type result struct {
// getBasicColumnsForTest - will return you all the columns within `result` that are needed for tests.
// * In here, we'll return if compositeKey=false - id (pk), email, first_name, last_name, created_at, toast_text (TOAST-able)
// * Else if compositeKey=true - id(pk), email (pk), first_name, last_name, created_at, toast_text (TOAST-able)
func getBasicColumnsForTest(compositeKey bool, uppercaseEscNames bool) result {
func getBasicColumnsForTest(compositeKey bool) result {
idCol := columns.NewColumn("id", typing.Float)
emailCol := columns.NewColumn("email", typing.String)
textToastCol := columns.NewColumn("toast_text", typing.String)
Expand All @@ -47,10 +47,10 @@ func getBasicColumnsForTest(compositeKey bool, uppercaseEscNames bool) result {
cols.AddColumn(columns.NewColumn(constants.DeleteColumnMarker, typing.Boolean))

var pks []columns.Wrapper
pks = append(pks, columns.NewWrapper(idCol, uppercaseEscNames, constants.Redshift))
pks = append(pks, columns.NewWrapper(idCol, false, constants.Redshift))

if compositeKey {
pks = append(pks, columns.NewWrapper(emailCol, uppercaseEscNames, constants.Redshift))
pks = append(pks, columns.NewWrapper(emailCol, false, constants.Redshift))
}

return result{
Expand All @@ -65,7 +65,7 @@ func TestMergeStatementParts_SkipDelete(t *testing.T) {
// 2. There are 3 SQL queries (INSERT, UPDATE and DELETE)
fqTableName := "public.tableName"
tempTableName := "public.tableName__temp"
res := getBasicColumnsForTest(false, false)
res := getBasicColumnsForTest(false)
mergeArg := &MergeArgument{
TableID: MockTableIdentifier{fqTableName},
SubQuery: tempTableName,
Expand All @@ -92,7 +92,7 @@ func TestMergeStatementParts_SkipDelete(t *testing.T) {
func TestMergeStatementPartsSoftDelete(t *testing.T) {
fqTableName := "public.tableName"
tempTableName := "public.tableName__temp"
res := getBasicColumnsForTest(false, false)
res := getBasicColumnsForTest(false)
mergeArg := &MergeArgument{
TableID: MockTableIdentifier{fqTableName},
SubQuery: tempTableName,
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestMergeStatementPartsSoftDelete(t *testing.T) {
func TestMergeStatementPartsSoftDeleteComposite(t *testing.T) {
fqTableName := "public.tableName"
tempTableName := "public.tableName__temp"
res := getBasicColumnsForTest(true, false)
res := getBasicColumnsForTest(true)
mergeArg := &MergeArgument{
TableID: MockTableIdentifier{fqTableName},
SubQuery: tempTableName,
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestMergeStatementParts(t *testing.T) {
// 2. There are 3 SQL queries (INSERT, UPDATE and DELETE)
fqTableName := "public.tableName"
tempTableName := "public.tableName__temp"
res := getBasicColumnsForTest(false, false)
res := getBasicColumnsForTest(false)
mergeArg := &MergeArgument{
TableID: MockTableIdentifier{fqTableName},
SubQuery: tempTableName,
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestMergeStatementParts(t *testing.T) {
func TestMergeStatementPartsCompositeKey(t *testing.T) {
fqTableName := "public.tableName"
tempTableName := "public.tableName__temp"
res := getBasicColumnsForTest(true, false)
res := getBasicColumnsForTest(true)
mergeArg := &MergeArgument{
TableID: MockTableIdentifier{fqTableName},
SubQuery: tempTableName,
Expand Down
24 changes: 12 additions & 12 deletions lib/destination/dml/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func TestMergeStatement(t *testing.T) {
TableID: MockTableIdentifier{fqTable},
SubQuery: subQuery,
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,
SoftDelete: false,
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
}

mergeSQL, err := mergeArg.GetStatement()
Expand All @@ -125,10 +125,10 @@ func TestMergeStatement(t *testing.T) {
assert.Contains(t, mergeSQL, "AS cc ON c.id = cc.id", mergeSQL)

// Check setting for update
assert.Contains(t, mergeSQL, `SET id=cc.id,bar=cc.bar,updated_at=cc.updated_at,"start"=cc."start"`, mergeSQL)
assert.Contains(t, mergeSQL, `SET id=cc.id,bar=cc.bar,updated_at=cc.updated_at,"START"=cc."START"`, mergeSQL)
// Check for INSERT
assert.Contains(t, mergeSQL, `id,bar,updated_at,"start"`, mergeSQL)
assert.Contains(t, mergeSQL, `cc.id,cc.bar,cc.updated_at,cc."start"`, mergeSQL)
assert.Contains(t, mergeSQL, `id,bar,updated_at,"START"`, mergeSQL)
assert.Contains(t, mergeSQL, `cc.id,cc.bar,cc.updated_at,cc."START"`, mergeSQL)
}

func TestMergeStatementIdempotentKey(t *testing.T) {
Expand Down Expand Up @@ -250,24 +250,24 @@ func TestMergeStatementEscapePrimaryKeys(t *testing.T) {
SubQuery: subQuery,
IdempotentKey: "",
PrimaryKeys: []columns.Wrapper{
columns.NewWrapper(columns.NewColumn("id", typing.Invalid), false, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("group", typing.Invalid), false, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("id", typing.Invalid), true, constants.Snowflake),
columns.NewWrapper(columns.NewColumn("group", typing.Invalid), true, constants.Snowflake),
},
Columns: &_cols,
DestKind: constants.Snowflake,
SoftDelete: false,
UppercaseEscNames: ptr.ToBool(false),
UppercaseEscNames: ptr.ToBool(true),
}

mergeSQL, err := mergeArg.GetStatement()
assert.NoError(t, err)
assert.Contains(t, mergeSQL, fmt.Sprintf("MERGE INTO %s", fqTable), mergeSQL)
assert.NotContains(t, mergeSQL, fmt.Sprintf("cc.%s >= c.%s", "updated_at", "updated_at"), fmt.Sprintf("Idempotency key: %s", mergeSQL))
// Check primary keys clause
assert.Contains(t, mergeSQL, `AS cc ON c.id = cc.id and c."group" = cc."group"`, mergeSQL)
assert.Contains(t, mergeSQL, `AS cc ON c.id = cc.id and c."GROUP" = cc."GROUP"`, mergeSQL)
// Check setting for update
assert.Contains(t, mergeSQL, `SET id=cc.id,"group"=cc."group",updated_at=cc.updated_at,"start"=cc."start"`, mergeSQL)
assert.Contains(t, mergeSQL, `SET id=cc.id,"GROUP"=cc."GROUP",updated_at=cc.updated_at,"START"=cc."START"`, mergeSQL)
// Check for INSERT
assert.Contains(t, mergeSQL, `id,"group",updated_at,"start"`, mergeSQL)
assert.Contains(t, mergeSQL, `cc.id,cc."group",cc.updated_at,cc."start"`, mergeSQL)
assert.Contains(t, mergeSQL, `id,"GROUP",updated_at,"START"`, mergeSQL)
assert.Contains(t, mergeSQL, `cc.id,cc."GROUP",cc.updated_at,cc."START"`, mergeSQL)
}
10 changes: 5 additions & 5 deletions lib/typing/columns/columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestColumn_Name(t *testing.T) {
{
colName: "start",
expectedName: "start",
expectedNameEsc: `"start"`, // since this is a reserved word.
expectedNameEsc: `"START"`, // since this is a reserved word.
expectedNameEscBq: "`start`", // BQ escapes via backticks.
},
{
Expand All @@ -169,7 +169,7 @@ func TestColumn_Name(t *testing.T) {

assert.Equal(t, testCase.expectedName, col.RawName(), testCase.colName)

assert.Equal(t, testCase.expectedNameEsc, col.Name(false, constants.Snowflake), testCase.colName)
assert.Equal(t, testCase.expectedNameEsc, col.Name(true, constants.Snowflake), testCase.colName)
assert.Equal(t, testCase.expectedNameEscBq, col.Name(false, constants.BigQuery), testCase.colName)
}
}
Expand Down Expand Up @@ -265,13 +265,13 @@ func TestColumns_GetEscapedColumnsToUpdate(t *testing.T) {
{
name: "happy path",
cols: happyPathCols,
expectedColsEsc: []string{"hi", "bye", `"start"`},
expectedColsEsc: []string{"hi", "bye", `"START"`},
expectedColsEscBq: []string{"hi", "bye", "`start`"},
},
{
name: "happy path + extra col",
cols: extraCols,
expectedColsEsc: []string{"hi", "bye", `"start"`},
expectedColsEsc: []string{"hi", "bye", `"START"`},
expectedColsEscBq: []string{"hi", "bye", "`start`"},
},
}
Expand All @@ -281,7 +281,7 @@ func TestColumns_GetEscapedColumnsToUpdate(t *testing.T) {
columns: testCase.cols,
}

assert.Equal(t, testCase.expectedColsEsc, cols.GetEscapedColumnsToUpdate(false, constants.Snowflake), testCase.name)
assert.Equal(t, testCase.expectedColsEsc, cols.GetEscapedColumnsToUpdate(true, constants.Snowflake), testCase.name)
assert.Equal(t, testCase.expectedColsEscBq, cols.GetEscapedColumnsToUpdate(false, constants.BigQuery), testCase.name)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/typing/columns/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func TestWrapper_Complete(t *testing.T) {
{
name: "group",
expectedRawName: "group",
expectedEscapedName: `"group"`,
expectedEscapedName: `"GROUP"`,
expectedEscapedNameBQ: "`group`",
},
}

for _, testCase := range testCases {
// Snowflake escape
w := NewWrapper(NewColumn(testCase.name, typing.Invalid), false, constants.Snowflake)
w := NewWrapper(NewColumn(testCase.name, typing.Invalid), true, constants.Snowflake)

assert.Equal(t, testCase.expectedEscapedName, w.EscapedName(), testCase.name)
assert.Equal(t, testCase.expectedRawName, w.RawName(), testCase.name)
Expand Down

0 comments on commit 6bd7d2d

Please sign in to comment.