-
Notifications
You must be signed in to change notification settings - Fork 67
V4 schema revisions candidate #903
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
Merged
krivard
merged 13 commits into
v4-schema-revisions-release-prep
from
v4-schema-revisions-release-prep-prep
Jun 15, 2022
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
40616e2
wip removals
melange396 a9e0dcf
old schema removal
melange396 c7ae2d0
new schema addition, plus source and test changes to go with it
melange396 a3288c7
administrativa (requirement version pinning & ignore filespec)
melange396 61a3d8b
fixed functionality and testing for delete_batch feature
melange396 3f27050
Update integrations/server/test_covidcast_endpoints.py
melange396 43fc1da
Update src/acquisition/covidcast/database.py
melange396 fd3d03f
Update src/server/endpoints/covidcast.py
melange396 0fceb43
changes from comments on PR
melange396 33dfbde
Apply suggestions from code review & discussion
krivard 1f2c175
Switch to CREATE TABLE SELECT for signal_latest
krivard c9a2708
Remove dev setup from prod v4 DDL
krivard 7e28e0f
Specify schema for each DDL file
krivard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| *~ | ||
| \#*# | ||
| .DS_Store | ||
| /.vscode | ||
| /delphi-epidata | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| geo_id,value,stderr,sample_size,issue,time_value,geo_type,signal,source | ||
| d_nonlatest,0,0,0,1,0,geo,sig,src | ||
| d_latest, 0,0,0,3,0,geo,sig,src | ||
| d_latest, 0,0,0,3,0,geo,sig,src | ||
| d_justone, 0,0,0,1,0,geo,sig,src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import unittest | ||
|
|
||
| from delphi_utils import Nans | ||
| from delphi.epidata.acquisition.covidcast.database import Database, CovidcastRow | ||
| import delphi.operations.secrets as secrets | ||
|
|
||
| # all the Nans we use here are just one value, so this is a shortcut to it: | ||
| nmv = Nans.NOT_MISSING.value | ||
|
|
||
| class TestTest(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| # use the local test instance of the database | ||
| secrets.db.host = 'delphi_database_epidata' | ||
| secrets.db.epi = ('user', 'pass') | ||
|
|
||
| self._db = Database() | ||
| self._db.connect() | ||
|
|
||
| # empty all of the data tables | ||
| for table in "signal_load signal_latest signal_history geo_dim signal_dim".split(): | ||
| self._db._cursor.execute(f"TRUNCATE TABLE {table}") | ||
|
|
||
| def tearDown(self): | ||
| # close and destroy conenction to the database | ||
| self._db.disconnect(False) | ||
| del self._db | ||
|
|
||
| def _make_dummy_row(self): | ||
| return CovidcastRow('src', 'sig', 'day', 'state', 2022_02_22, 'pa', 2, 22, 222, nmv,nmv,nmv, 2022_02_22, 0) | ||
| # cols: ^ timeval v se ssz ^issue ^lag | ||
|
|
||
| def _insert_rows(self, rows): | ||
| # inserts rows into the database using the full acquisition process, including 'dbjobs' load into history & latest tables | ||
| self._db.insert_or_update_bulk(rows) | ||
| self._db.run_dbjobs() | ||
| ###db._connection.commit() # NOTE: this isnt needed here, but would be if using external access (like through client lib) | ||
|
|
||
| def _find_matches_for_row(self, row): | ||
| # finds (if existing) row from both history and latest views that matches long-key of provided CovidcastRow | ||
| # TODO: consider making `issue` an optional match... this will break the at-most-1-row-returned assumption for signal_history | ||
| cols = "source signal time_type time_value geo_type geo_value issue".split() | ||
| results = {} | ||
| cur = self._db._cursor | ||
| for table in ['signal_latest_v', 'signal_history_v']: | ||
| q = f"SELECT * FROM {table} WHERE " | ||
| # NOTE: repr() puts str values in single quotes but simply 'string-ifies' numerics; | ||
| # getattr() accesses members by string of their name | ||
| q += " AND ".join([f" `{c}` = {repr(getattr(row,c))} " for c in cols]) | ||
| q += " LIMIT 1;" | ||
| cur.execute(q) | ||
| res = cur.fetchone() | ||
| if res: | ||
| results[table] = dict(zip(cur.column_names, res)) | ||
| else: | ||
| results[table] = None | ||
| return results | ||
|
|
||
| def test_id_sync(self): | ||
| # the history and latest tables have a non-AUTOINCREMENT primary key id that is fed by the | ||
| # AUTOINCREMENT pk id from the load table. this test is intended to make sure that they | ||
| # appropriately stay in sync with each other | ||
|
|
||
| pk_column = 'signal_data_id' | ||
| histor_view = 'signal_history_v' | ||
| latest_view = 'signal_latest_v' | ||
|
|
||
| # add a data point | ||
| base_row = self._make_dummy_row() | ||
| self._insert_rows([base_row]) | ||
| # ensure the primary keys match in the latest and history tables | ||
| matches = self._find_matches_for_row(base_row) | ||
| self.assertEqual(matches[latest_view][pk_column], | ||
| matches[histor_view][pk_column]) | ||
| # save old pk value | ||
| old_pk_id = matches[latest_view][pk_column] | ||
|
|
||
| # add a reissue for said data point | ||
| next_row = self._make_dummy_row() | ||
| next_row.issue += 1 | ||
| self._insert_rows([next_row]) | ||
| # ensure the new keys also match | ||
| matches = self._find_matches_for_row(next_row) | ||
| self.assertEqual(matches[latest_view][pk_column], | ||
| matches[histor_view][pk_column]) | ||
| # check new ids were used | ||
| new_pk_id = matches[latest_view][pk_column] | ||
| self.assertNotEqual(old_pk_id, new_pk_id) | ||
|
|
||
| # verify old issue is no longer in latest table | ||
| self.assertIsNone(self._find_matches_for_row(base_row)[latest_view]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.