-
Notifications
You must be signed in to change notification settings - Fork 30
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
Improve Snowflake Dedupe. #500
Conversation
clients/snowflake/snowflake.go
Outdated
return err | ||
var parts []string | ||
parts = append(parts, fmt.Sprintf("CREATE OR REPLACE TRANSIENT TABLE %s AS (SELECT * FROM %s QUALIFY ROW_NUMBER() OVER (PARTITION BY by %s ORDER BY %s) = 2)", | ||
stagingTableID.Table(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use stagingTableID.FullyQualifiedName()
or escape stagingTableID.Table()
with sql.EscapeName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a transient table, it doesn't belong to a schema or database.
clients/snowflake/snowflake.go
Outdated
for _, pk := range orderColsToIterate { | ||
orderByCols = append(orderByCols, fmt.Sprintf("%s ASC", pk)) | ||
} | ||
|
||
fqTableName := tableID.FullyQualifiedName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tableID.FullyQualifiedName()
is so short now that it doesn't take arguments we could just inline it instead of assigning to fqTableName
.
clients/snowflake/snowflake.go
Outdated
|
||
parts = append(parts, fmt.Sprintf("DELETE FROM %s t1 USING %s t2 WHERE %s", | ||
fqTableName, | ||
stagingTableID.Table(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto escape or use FullyQualifiedName()
.
{ | ||
// Dedupe with one primary key + no `__artie_updated_at` flag. | ||
tableID := NewTableIdentifier("db", "public", "customers") | ||
stagingTableID := shared.TempTableID(tableID, strings.ToLower(stringutil.Random(5))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to have two methods TempTableID
and TempTableIDWithSuffix
.
@nathan-artie Take another look? Should be good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Improving our Snowflake dedupe process which will minimize data movement from the target table, which will execute faster and more reliably.