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

Soft Delete bug #740

Merged
merged 4 commits into from
Jun 18, 2024
Merged

Soft Delete bug #740

merged 4 commits into from
Jun 18, 2024

Conversation

Tang8330
Copy link
Contributor

@Tang8330 Tang8330 commented Jun 18, 2024

Context

Transfer leverages an in-memory database that is key-value based.

The key being the primary key(s) of the table and the value is the latest row as we leverage Kafka for ordering guarantee.

Problem

The problem is that if there are 2 events within one flush cycle say:

  • t0, event was created for id = 1
  • t1, event was deleted for id = 1

When we flush, we'll only have the latest deleted row. Our merge logic for handling soft deletes was incorrect as it wrongfully assumed that the row should be in the target table.

MERGE INTO foo.public."bar" tgt USING ( foo.public."bar" ) AS stg ON tgt."id" = stg."id" AND tgt."user_id" = stg."user_id"
WHEN MATCHED THEN UPDATE SET "id"=stg."id","user_id"=stg."user_id","__ARTIE_DELETE"=stg."__ARTIE_DELETE","__ARTIE_UPDATED_AT"=stg."__ARTIE_UPDATED_AT"
WHEN NOT MATCHED AND IFNULL(foo.__ARTIE_DELETE, false) = false THEN INSERT ("id","user_id","__ARTIE_DELETE","__ARTIE_UPDATED_AT") VALUES (stg."id",stg."user_id",stg."__ARTIE_DELETE",stg."__ARTIE_UPDATED_AT");

We fixed this by changing WHEN NOT MATCHED AND IFNULL(foo.__ARTIE_DELETE, false) = false to be WHEN NOT MATCHED

@Tang8330 Tang8330 marked this pull request as ready for review June 18, 2024 02:59
@Tang8330 Tang8330 changed the title [Soft Delete] Fixing bug Soft Delete bug Jun 18, 2024
@@ -158,6 +159,8 @@ func Merge(dwh destination.DataWarehouse, tableData *optimization.TableData, opt
return fmt.Errorf("failed to generate merge statements: %w", err)
}

fmt.Println("mergeStatements", mergeStatements)
Copy link
Contributor

Choose a reason for hiding this comment

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

Print statement.

@Tang8330 Tang8330 merged commit 6b979d7 into master Jun 18, 2024
1 check passed
@Tang8330 Tang8330 deleted the soft-delete-bug branch June 18, 2024 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants