-
Notifications
You must be signed in to change notification settings - Fork 67
Added UNIQUE KEYS to fluview_clinical to avoid duplicates #1127
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
Added UNIQUE KEYS to fluview_clinical to avoid duplicates #1127
Conversation
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.
looks great! you might want to consider adding a new .sql file in src/ddl/migrations/
that has an ALTER TABLE
statement to add the new index (and another to delete the old one).
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.
Escalating George's request for a migrations file; for this it's required
Kudos, SonarCloud Quality Gate passed! |
…l table. Added new constraint creation
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.
Dmytro and i talked about some other ways to approach this, he will probably be updating the migration file sometime soon.
…alculation correct. Changed issue to release_date in ON DUPLICATE KEY UPDATE secion for table.
…pulate it with only unique rows from original `fluview_clinical` table. Added statement to remove duplicates from `fluview_clinical` table. Added `issue` index drop on `fluview_clinical` table with with the following creation of new one that is based on (`issue`, `epiweek`, `region`).
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.
looks great! just a few things for the paste/typo, adding 2 comments, and doing the table drop+rename!
-- Before creating new unique constraint we need to remove rows that do not satisfy it. | ||
DELETE FROM | ||
fluview_clinical | ||
WHERE |
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 just a reminder that we can remove the fluview_clinical
table, and then rename fluview_clinical_v2
back to fluview_clinical
instead of this
Co-authored-by: melange396 <[email protected]>
Co-authored-by: melange396 <[email protected]>
Kudos, SonarCloud Quality Gate passed!
|
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.
👍
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.
👍 solid!
closes
Prerequisites:
dev
branchdev
Summary
Added UNIQUE KEY constraints to epidata.fluview_clinical to avoid duplicate rows.
Before that, we need to delete duplicates:
DELETE FROM fluview_clinical WHERE id in ( SELECT dup.id FROM ( SELECT * FROM ( SELECT fc.id, fc.release_date, fc.issue, fc.epiweek, fc.region, fc.lag, fc.total_specimens, fc.total_a, fc.total_b, fc.percent_positive, fc.percent_a, fc.percent_b, ROW_NUMBER() OVER ( PARTITION BY fc.release_date,fc.issue,fc.epiweek,fc.region,fc.lag,fc.total_specimens,fc.total_a,fc.total_b,fc.percent_positive,fc.percent_a,fc.percent_b ORDER BY fc.release_date ) as row_num FROM epidata.fluview_clinical fc ORDER BY fc.release_date DESC ) s WHERE s.row_num > 1 ) dup );