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

script/delete_records: Add option to match fields with regex pattern #151

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions scripts/delete_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
parser.add_argument("-db", "--database", help="database to delete from")
parser.add_argument("-v", "--virus", default="flu", help="virus table to interact with")
parser.add_argument("--filter", nargs="*", default=[], help="Filters for records to delete, i.e. inclusion_date: 2021-02-12")
parser.add_argument("--match", nargs="*", default=[], help="Match for records to delete with regex pattern, e.g. accession:^EPIEPI")
parser.add_argument('--interval', nargs="*", default=[], help="Select date interval of values for fields, e.g. assay_date:2019-09-03,2023-10-25")
parser.add_argument("--preview", action="store_true", help="Preview records to be deleted without deleting from db.")

Expand All @@ -29,6 +30,14 @@

rethinkdb_command = r.table(args.virus).filter(delete_filters)

delete_matches = {}
for delete_match in args.match:
field, pattern = delete_match.split(":")
rethinkdb_command = rethinkdb_command.filter(lambda doc: doc[field].match(pattern))
delete_matches[field] = pattern

print(f"Delete matches: {delete_matches}")

delete_intervals = {}
for interval in args.interval:
field, values = interval.split(':')
Expand Down