-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Noel Gomez
committed
Sep 23, 2023
1 parent
a1af9f5
commit 7b06e46
Showing
4 changed files
with
45 additions
and
38 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
75 changes: 41 additions & 34 deletions
75
transform/models/L2_bays/covid_observations/covid_location.sql
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 |
---|---|---|
@@ -1,40 +1,47 @@ | ||
{{ config(materialized="view") }} | ||
|
||
with | ||
jhu_covid_19 as ( | ||
select distinct | ||
country_region, | ||
coalesce(province_state, 'UNDEFINED') as province_state, | ||
coalesce(county, 'UNDEFINED') as county, | ||
lat, | ||
long, | ||
iso3166_1, | ||
iso3166_2, | ||
date | ||
from {{ ref("jhu_covid_19") }} | ||
), | ||
with jhu_covid_19 as ( | ||
select distinct | ||
country_region, | ||
coalesce(province_state, 'UNDEFINED') as province_state, | ||
coalesce(county, 'UNDEFINED') as county, | ||
lat, | ||
long, | ||
iso3166_1, | ||
iso3166_2, | ||
date | ||
from {{ ref("jhu_covid_19") }} | ||
), | ||
|
||
rank_locations as ( | ||
select | ||
hash( | ||
country_region || '|' || province_state || '|' || county | ||
) as snowflake_location_id, | ||
{{ | ||
dbt_utils.generate_surrogate_key( | ||
["country_region", "province_state", "county"] | ||
) | ||
}} as location_id, | ||
country_region as country, | ||
province_state as state, | ||
county, | ||
lat, | ||
long, | ||
iso3166_1, | ||
iso3166_2, | ||
rank() over (partition by location_id order by date desc) as rowrank | ||
from jhu_covid_19 | ||
) | ||
rank_locations as ( | ||
select | ||
hash( | ||
country_region || '|' || province_state || '|' || county | ||
) as snowflake_location_id, | ||
{{ | ||
dbt_utils.generate_surrogate_key( | ||
["country_region", "province_state", "county"] | ||
) | ||
}} as location_id, | ||
country_region as country, | ||
province_state as state, | ||
county, | ||
lat, | ||
long, | ||
iso3166_1, | ||
iso3166_2, | ||
rank() over (partition by location_id order by date desc) as rowrank | ||
from jhu_covid_19 | ||
) | ||
|
||
select location_id, country, state, county, lat, long, iso3166_1, iso3166_2 | ||
select | ||
location_id, | ||
country, | ||
state, | ||
county, | ||
lat, | ||
long, | ||
iso3166_1, | ||
iso3166_2 | ||
from rank_locations | ||
where rowrank = 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
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