-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first batch of v2 schema scripts
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,23 @@ | ||
CREATE OR REPLACE TABLE FUNCTION `clinvar_ingest.all_schemas_v2`() | ||
AS ( | ||
-- the state of al clinvar schemas available at the moment | ||
SELECT | ||
r.schema_name, | ||
r.release_date, | ||
LAG(r.release_date, 1, DATE('0001-01-01')) OVER (ORDER BY r.release_date ASC) AS prev_release_date, | ||
LEAD(r.release_date, 1, DATE('9999-12-31')) OVER (ORDER BY r.release_date ASC) AS next_release_date | ||
FROM ( | ||
|
||
SELECT | ||
iss.schema_name, | ||
CAST(REGEXP_REPLACE(iss.schema_name, r'clinvar_(\d{4})_(\d{2})_(\d{2}).*', '\\1-\\2-\\3') as DATE) AS release_date | ||
FROM INFORMATION_SCHEMA.SCHEMATA iss | ||
WHERE | ||
( | ||
REGEXP_CONTAINS(iss.schema_name, r'^clinvar_\d{4}_\d{2}_\d{2}_v2_\d+_\d+$') | ||
OR | ||
REGEXP_CONTAINS(iss.schema_name, r'^clinvar_\d{4}_\d{2}_\d{2}_v2_\d+_\d+_(alpha|beta)\d*$') | ||
) | ||
) r | ||
ORDER BY 2 | ||
); |
This file contains 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,15 @@ | ||
CREATE OR REPLACE TABLE FUNCTION `clinvar_ingest.schema_on_v2`(on_date DATE) | ||
AS ( | ||
-- the state of schemas available on a certain date | ||
-- if the date lands on a schema release date then that will be the schema | ||
-- otherwise the schema with the release date just prior to that date will be the schema | ||
SELECT | ||
x.schema_name, | ||
x.release_date, | ||
x.prev_release_date, | ||
x.next_release_date | ||
FROM `clinvar_ingest.all_schemas_v2`() x | ||
WHERE on_date >= x.release_date | ||
ORDER BY 2 DESC | ||
LIMIT 1 | ||
); |
This file contains 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,17 @@ | ||
CREATE OR REPLACE TABLE FUNCTION `clinvar_ingest.schemas_on_or_after_v2`(on_or_after_date DATE) | ||
AS ( | ||
-- the state of schemas available on or after a certain date | ||
-- if the date lands on a schema release date then that will be the first schema | ||
-- if the date is prior to the earliest release date then return all schemas | ||
-- otherwise the schema with the release date just prior to that date will be the first schema | ||
SELECT | ||
x.schema_name, | ||
x.release_date, | ||
x.prev_release_date, | ||
x.next_release_date | ||
FROM `clinvar_ingest.all_schemas_v2`() x | ||
WHERE (on_or_after_date > x.prev_release_date AND on_or_after_date < x.next_release_date) OR on_or_after_date <= x.release_date | ||
ORDER BY 2 | ||
); | ||
|
||
-- select * from `clinvar_ingest.schemas_on_or_after`(DATE('2020-06-01')); |
This file contains 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,16 @@ | ||
CREATE OR REPLACE TABLE FUNCTION `clinvar_ingest.schemas_on_or_before_v2`(on_or_before_date DATE) | ||
AS ( | ||
-- the state of schemas available on or before a certain date | ||
-- if the date lands on a schema release date then that will be the last schema | ||
-- otherwise the schema with the release date just prior to that date will be the last schema | ||
SELECT | ||
x.schema_name, | ||
x.release_date, | ||
x.prev_release_date, | ||
x.next_release_date | ||
FROM `clinvar_ingest.all_schemas_v2`() x | ||
WHERE on_or_before_date >= x.release_date | ||
ORDER BY 2 | ||
); | ||
|
||
-- select * from `clinvar_ingest.schemas_on_or_before`(DATE('2020-06-01')); |