Skip to content

Commit cfc5f51

Browse files
authored
Fix/country name hoc events (#264)
2 parents 7f5749d + 3089709 commit cfc5f51

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

dbt/macros/country_normalization.sql

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
{% macro country_normalization(raw_country_name) %}
22
case
3-
when lower({{raw_country_name }}) in ('åland') then 'åland islands'
3+
when lower({{raw_country_name }}) in ('åland','aland islands') then 'åland islands'
4+
when lower({{raw_country_name }}) in ('antigua & barbuda') then 'antigua and barbuda'
5+
when lower({{raw_country_name }}) in ('the bahamas') then 'bahamas'
6+
when lower({{raw_country_name }}) in ('caribbean netherlands') then 'bonaire, sint eustatius, and saba'
7+
when lower({{raw_country_name }}) in ('bosnia herzegovina','bosnia & herzegovina') then 'bosnia and herzegovina'
48
when lower({{raw_country_name }}) in ('brunei') then 'brunei darussalam'
59
when lower({{raw_country_name }}) in ('cape verde') then 'cabo verde'
610
when lower({{raw_country_name }}) in ('cocos [keeling] islands') then 'cocos (keeling) islands'
7-
when lower({{raw_country_name }}) in ('dr congo','congo','congo, the democratic republic of the') then 'congo, democratic republic of'
11+
when lower({{raw_country_name }}) in ('dr congo','congo','congo, the democratic republic of the','democratic republic of congo','democratic republic of the congo') then 'congo, democratic republic of'
812
when lower({{raw_country_name }}) in ('republic of the congo','congo republic') then 'congo, republic of'
913
when lower({{raw_country_name }}) in ('ivory coast','cote d''ivoire') then 'côte d''ivoire'
1014
when lower({{raw_country_name }}) in ('czech republic') then 'czechia'
1115
when lower({{raw_country_name }}) in ('swaziland') then 'eswatini'
16+
when lower({{raw_country_name }}) in ('falkland islands (islas malvinas)') then 'falkland islands'
17+
when lower({{raw_country_name }}) in ('the gambia') then 'gambia'
1218
when lower({{raw_country_name }}) in ('iran, islamic republic of') then 'iran'
1319
when lower({{raw_country_name }}) in ('hashemite kingdom of jordan') then 'jordan'
20+
when lower({{raw_country_name }}) in ('republic of kosovo') then 'kosovo'
1421
when lower({{raw_country_name }}) in ('lao people''s democratic republic') then 'laos'
1522
when lower({{raw_country_name }}) in ('republic of lithuania') then 'lithuania'
1623
when lower({{raw_country_name }}) in ('macau') then 'macao'
17-
when lower({{raw_country_name }}) in ('federated states of micronesia') then 'micronesia, federated states of'
24+
when lower({{raw_country_name }}) in ('federated states of micronesia','micronesia') then 'micronesia, federated states of'
1825
when lower({{raw_country_name }}) in ('republic of moldova','moldova') then 'moldova, republic of'
1926
when lower({{raw_country_name }}) in ('principality of monaco') then 'monaco'
20-
when lower({{raw_country_name }}) in ('myanmar [burma]') then 'myanmar'
27+
when lower({{raw_country_name }}) in ('myanmar [burma]','republic of the union of myanmar','myanmar (burma)') then 'myanmar'
2128
when lower({{raw_country_name }}) in ('the netherlands') then 'netherlands'
2229
when lower({{raw_country_name }}) in ('korea, democratic people''s republic of') then 'north korea'
23-
when lower({{raw_country_name }}) in ('macedonia') then 'north macedonia'
24-
when lower({{raw_country_name }}) in ('palestinian territory') then 'palestine'
30+
when lower({{raw_country_name }}) in ('macedonia','macedonia (fyrom)') then 'north macedonia'
31+
when lower({{raw_country_name }}) in ('kingdom of norway') then 'norway'
32+
when lower({{raw_country_name }}) in ('palestinian territory','palestinian territories') then 'palestine'
33+
when lower({{raw_country_name }}) in ('pitcairn islands') then 'pitcairn'
34+
when lower({{raw_country_name }}) in ('reunion') then 'réunion'
2535
when lower({{raw_country_name }}) in ('russian federation') then 'russia'
26-
when lower({{raw_country_name }}) in ('saint-barthélemy','saint-barthélemy') then 'saint barthélemy'
27-
when lower({{raw_country_name }}) in ('saint helena') then 'saint helena, ascension, and tristan da cunha'
36+
when lower({{raw_country_name }}) in ('saint-barthélemy') then 'saint barthélemy'
37+
when lower({{raw_country_name }}) in ('saint helena','saint helena ascension and tristan da cunha') then 'saint helena, ascension, and tristan da cunha'
2838
when lower({{raw_country_name }}) in ('st kitts and nevis') then 'saint kitts and nevis'
39+
when lower({{raw_country_name }}) in ('collectivity of saint martin') then 'saint martin'
2940
when lower({{raw_country_name }}) in ('st vincent and grenadines') then 'saint vincent and the grenadines'
3041
when lower({{raw_country_name }}) in ('sao tome and principe') then 'são tomé and príncipe'
3142
when lower({{raw_country_name }}) in ('slovak republic') then 'slovakia'
3243
when lower({{raw_country_name }}) in ('republic of korea', 'korea, republic of') then 'south korea'
3344
when lower({{raw_country_name }}) in ('syrian arab republic') then 'syria'
3445
when lower({{raw_country_name }}) in ('tanzania, united republic of') then 'tanzania'
35-
when lower({{raw_country_name }}) in ('democratic republic of timor-leste','east timor') then 'timor-leste'
46+
when lower({{raw_country_name }}) in ('democratic republic of timor-leste','east timor','timor leste') then 'timor-leste'
3647
when lower({{raw_country_name }}) in ('turkey') then 'türkiye'
48+
when lower({{raw_country_name }}) in ('northern ireland') then 'united kingdom'
3749
when lower({{raw_country_name }}) in ('u.s. minor outlying islands') then 'united states minor outlying islands'
50+
when lower({{raw_country_name }}) in ('us virgin islands') then 'u.s. virgin islands'
3851
when {{raw_country_name}} = '' then NULL
3952
else lower({{raw_country_name }})
4053
end

dbt/models/staging/pegasus_pii/stg_pegasus_pii__form_geos.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
with
22
form_geos as (
3-
select *
3+
select
4+
form_geo_id,
5+
form_id,
6+
created_at,
7+
updated_at,
8+
lower(city) as city,
9+
lower(state) as state,
10+
{{country_normalization('country')}} as country,
11+
postal_code
412
from {{ ref('base_pegasus_pii__form_geos') }}
513
)
614

dbt/models/staging/pegasus_pii/stg_pegasus_pii__forms.sql

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,29 @@ forms as (
4343
from {{ ref('base_pegasus_pii__forms') }}
4444
)
4545

46-
select *
47-
from forms
46+
select
47+
form_id,
48+
form_category,
49+
hoc_year,
50+
email,
51+
name,
52+
form_kind,
53+
created_at,
54+
updated_at,
55+
indexed_at,
56+
review,
57+
reviewed_by,
58+
reviewed_at,
59+
processed_at,
60+
notified_at,
61+
user_id,
62+
parent_id,
63+
location_country_code,
64+
city,
65+
state,
66+
{{ country_normalization('country')}} as country,
67+
event_type,
68+
email_pref,
69+
special_event_flag
70+
from forms
71+

0 commit comments

Comments
 (0)