Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mssql] Escape all columns that do not start with "__artie" #501

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 0 additions & 190 deletions lib/config/constants/mssql.go

This file was deleted.

6 changes: 3 additions & 3 deletions lib/destination/dml/merge_mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func Test_GetMSSQLStatement(t *testing.T) {
mergeSQL, err := mergeArg.GetMSSQLStatement()
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))
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", mergeSQL)

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)
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, `cc."id",cc."bar",cc."updated_at",cc."start"`, mergeSQL)
}
2 changes: 1 addition & 1 deletion lib/sql/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NeedsEscaping(name string, destKind constants.DestinationKind) bool {
if destKind == constants.Redshift {
reservedKeywords = constants.RedshiftReservedKeywords
} else if destKind == constants.MSSQL {
reservedKeywords = constants.MSSQLReservedKeywords
return !strings.HasPrefix(name, constants.ArtiePrefix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just escape all?

Copy link
Contributor Author

@nathan-artie nathan-artie Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to but if we escape all columns we get test errors that say artie delete flag doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing there must be some places where we escape the column names and then check if the column names contain a specific value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a guardrail in dml/merge

Copy link
Contributor

@Tang8330 Tang8330 Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison is running "__artie_deleted" == __artie_deleted which will always equate to false

} else {
reservedKeywords = constants.ReservedKeywords
}
Expand Down