Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed May 2, 2024
1 parent 0028e0a commit 3517412
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/destination/dml/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ func (m *MergeArgument) GetParts() ([]string, error) {
equalitySQLParts = append(equalitySQLParts, equalitySQL)
}

cols := m.Columns.GetColumnsToUpdate()
columns := m.Columns.GetColumnsToUpdate()

if m.SoftDelete {
return []string{
// INSERT
fmt.Sprintf(`INSERT INTO %s (%s) SELECT %s FROM %s as cc LEFT JOIN %s as c on %s WHERE c.%s IS NULL;`,
// insert into target (col1, col2, col3)
m.TableID.FullyQualifiedName(), strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
m.TableID.FullyQualifiedName(), strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
// SELECT cc.col1, cc.col2, ... FROM staging as CC
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
}), m.SubQuery,
Expand All @@ -129,7 +129,7 @@ func (m *MergeArgument) GetParts() ([]string, error) {

// We also need to remove __artie flags since it does not exist in the destination table
var removed bool
cols = slices.DeleteFunc(cols, func(col string) bool {
columns = slices.DeleteFunc(columns, func(col string) bool {
if col == constants.DeleteColumnMarker {
removed = true
return true
Expand All @@ -149,10 +149,10 @@ func (m *MergeArgument) GetParts() ([]string, error) {
// INSERT
fmt.Sprintf(`INSERT INTO %s (%s) SELECT %s FROM %s as cc LEFT JOIN %s as c on %s WHERE c.%s IS NULL;`,
// insert into target (col1, col2, col3)
m.TableID.FullyQualifiedName(), strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
m.TableID.FullyQualifiedName(), strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
// SELECT cc.col1, cc.col2, ... FROM staging as CC
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
}), m.SubQuery,
Expand Down Expand Up @@ -230,7 +230,7 @@ func (m *MergeArgument) GetStatement() (string, error) {
equalitySQLParts = append(equalitySQLParts, m.AdditionalEqualityStrings...)
}

cols := m.Columns.GetColumnsToUpdate()
columns := m.Columns.GetColumnsToUpdate()

if m.SoftDelete {
return fmt.Sprintf(`
Expand All @@ -241,17 +241,17 @@ WHEN NOT MATCHED AND IFNULL(cc.%s, false) = false THEN INSERT (%s) VALUES (%s);`
// Update + Soft Deletion
idempotentClause, m.Columns.UpdateQuery(m.Dialect, false),
// Insert
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
})), nil
}

// We also need to remove __artie flags since it does not exist in the destination table
var removed bool
cols = slices.DeleteFunc(cols, func(col string) bool {
columns = slices.DeleteFunc(columns, func(col string) bool {
if col == constants.DeleteColumnMarker {
removed = true
return true
Expand All @@ -273,9 +273,9 @@ WHEN NOT MATCHED AND IFNULL(cc.%s, false) = false THEN INSERT (%s) VALUES (%s);`
// Update
constants.DeleteColumnMarker, idempotentClause, m.Columns.UpdateQuery(m.Dialect, true),
// Insert
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
})), nil
Expand All @@ -298,7 +298,7 @@ func (m *MergeArgument) GetMSSQLStatement() (string, error) {
equalitySQLParts = append(equalitySQLParts, equalitySQL)
}

cols := m.Columns.GetColumnsToUpdate()
columns := m.Columns.GetColumnsToUpdate()

if m.SoftDelete {
return fmt.Sprintf(`
Expand All @@ -310,17 +310,17 @@ WHEN NOT MATCHED AND COALESCE(cc.%s, 0) = 0 THEN INSERT (%s) VALUES (%s);`,
// Update + Soft Deletion
idempotentClause, m.Columns.UpdateQuery(m.Dialect, false),
// Insert
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
})), nil
}

// We also need to remove __artie flags since it does not exist in the destination table
var removed bool
cols = slices.DeleteFunc(cols, func(col string) bool {
columns = slices.DeleteFunc(columns, func(col string) bool {
if col == constants.DeleteColumnMarker {
removed = true
return true
Expand All @@ -343,9 +343,9 @@ WHEN NOT MATCHED AND COALESCE(cc.%s, 1) = 0 THEN INSERT (%s) VALUES (%s);`,
// Update
constants.DeleteColumnMarker, idempotentClause, m.Columns.UpdateQuery(m.Dialect, true),
// Insert
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(cols, m.Dialect), ","),
constants.DeleteColumnMarker, strings.Join(sql.QuoteIdentifiers(columns, m.Dialect), ","),
array.StringsJoinAddPrefix(array.StringsJoinAddPrefixArgs{
Vals: sql.QuoteIdentifiers(cols, m.Dialect),
Vals: sql.QuoteIdentifiers(columns, m.Dialect),
Separator: ",",
Prefix: "cc.",
})), nil
Expand Down

0 comments on commit 3517412

Please sign in to comment.