-
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.
Feature/Contacts and StudentContactAssociations (#96)
* redraft * add student contact associations * switch from parent to contact * add comments about name change * can't use gsn_skey * add note about new fields * update changelog * use dbt utils surrogate key * use parents if contacts are not enabled * add docs * remove configurability * extract extenstions configured with parent naming too * fix bad syntax --------- Co-authored-by: rlittle08 <rlittle@edanalytics.org>
- Loading branch information
1 parent
3925f34
commit 4a49369
Showing
14 changed files
with
213 additions
and
5 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
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,45 @@ | ||
with contacts as ( | ||
{{ source_edfi3('contacts') }} | ||
), | ||
renamed as ( | ||
select | ||
tenant_code, | ||
api_year, | ||
pull_timestamp, | ||
file_row_number, | ||
last_modified_timestamp, | ||
filename, | ||
is_deleted, | ||
|
||
v:id::string as record_guid, | ||
v:contactUniqueId::string as contact_unique_id, | ||
v:personReference:personId::string as person_id, | ||
v:firstName::string as first_name, | ||
v:middleName::string as middle_name, | ||
v:lastSurname::string as last_name, | ||
v:maidenName::string as maiden_name, | ||
v:generationCodeSuffix::string as generation_code_suffix, | ||
v:personalTitlePrefix::string as personal_title_prefix, | ||
v:genderIdentity::string as gender_identity, | ||
v:preferredFirstName::string as preferred_first_name, | ||
v:preferredLastSurname::string as preferred_last_name, | ||
v:loginId::string as login_id, | ||
{{ extract_descriptor('v:sexDescriptor::string') }} as sex, | ||
{{ extract_descriptor('v:highestCompletedLevelOfEducationDescriptor::string') }} as highest_completed_level_of_education, | ||
{{ extract_descriptor('v:personReference:sourceSystemDescriptor::string') }} as person_source_system, | ||
-- references | ||
v:personReference as person_reference, | ||
-- unflattened lists | ||
v:addresses as v_addresses, | ||
v:internationalAddresses as v_international_addresses, | ||
v:electronicMails as v_electronic_mails, | ||
v:telephones as v_telephones, | ||
v:languages as v_languages, | ||
v:otherNames as v_other_names, | ||
v:personalIdentificationDocuments as v_personal_identification_documents, | ||
|
||
-- edfi extensions | ||
v:_ext as v_ext | ||
from contacts | ||
) | ||
select * from renamed |
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
30 changes: 30 additions & 0 deletions
30
models/staging/edfi_3/base/base_ef3__student_contact_associations.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
with student_contact_associations as ( | ||
{{ source_edfi3('student_contact_associations') }} | ||
), | ||
renamed as ( | ||
select | ||
tenant_code, | ||
api_year, | ||
pull_timestamp, | ||
last_modified_timestamp, | ||
file_row_number, | ||
filename, | ||
is_deleted, | ||
|
||
v:id::string as record_guid, | ||
v:contactPriority::int as contact_priority, | ||
v:contactRestrictions::string as contact_restrictions, | ||
v:emergencyContactStatus::boolean as is_emergency_contact, | ||
v:livesWith::boolean as is_living_with, | ||
v:primaryContactStatus::boolean as is_primary_contact, | ||
v:legalGuardian::boolean as is_legal_guardian, | ||
{{ extract_descriptor('v:relationDescriptor::string') }} as relation_type, | ||
-- references | ||
v:contactReference as contact_reference, | ||
v:studentReference as student_reference, | ||
|
||
-- edfi extensions | ||
v:_ext as v_ext | ||
from student_contact_associations | ||
) | ||
select * from renamed |
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
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,37 @@ | ||
with base_contacts as ( | ||
select * from {{ ref('base_ef3__contacts') }} | ||
where not is_deleted | ||
), | ||
base_parents as ( | ||
select * rename parent_unique_id as contact_unique_id | ||
from {{ ref('base_ef3__parents') }} | ||
where not is_deleted | ||
), | ||
-- parents were renamed to contacts in Data Standard v5.0 | ||
unioned as ( | ||
select * from base_contacts | ||
union | ||
select * from base_parents | ||
), | ||
keyed as ( | ||
select | ||
{{ dbt_utils.surrogate_key( | ||
[ | ||
'tenant_code', | ||
'lower(contact_unique_id)' | ||
] | ||
) }} as k_contact, | ||
unioned.* | ||
{{ extract_extension(model_name=[this.name, 'stg_ef3__parents'], flatten=True) }} | ||
from unioned | ||
), | ||
deduped as ( | ||
{{ | ||
dbt_utils.deduplicate( | ||
relation='keyed', | ||
partition_by='k_contact', | ||
order_by='api_year desc, pull_timestamp desc' | ||
) | ||
}} | ||
) | ||
select * from deduped |
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 @@ | ||
{{ flatten_addresses('stg_ef3__contacts', ['k_contact']) }} |
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 @@ | ||
{{ flatten_emails('stg_ef3__contacts', ['k_contact']) }} |
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 @@ | ||
{{ flatten_telephones('stg_ef3__contacts', ['k_contact']) }} |
41 changes: 41 additions & 0 deletions
41
models/staging/edfi_3/stage/stg_ef3__student_contact_associations.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
with base_stu_contact as ( | ||
select | ||
*, | ||
contact_reference:contactUniqueId as contact_unique_id | ||
from {{ ref('base_ef3__student_contact_associations') }} | ||
where not is_deleted | ||
), | ||
base_stu_parent as ( | ||
select | ||
*, | ||
parent_reference:parentUniqueId as contact_unique_id --rename to support union and key generation | ||
from {{ ref('base_ef3__student_parent_associations') }} | ||
where not is_deleted | ||
), | ||
-- parents were renamed to contacts in Data Standard v5.0 | ||
unioned as ( | ||
select * from base_stu_contact | ||
union | ||
select * from base_stu_parent | ||
), | ||
keyed as ( | ||
select | ||
{{ gen_skey('k_student') }}, | ||
-- we can't use the gen_skey macro here because we're bringing in the deprecated parents endpoint data, which contains a parentReference that won't work | ||
{{ dbt_utils.surrogate_key(['tenant_code', 'contact_unique_id']) }} as k_contact, | ||
{{ gen_skey('k_student_xyear') }}, | ||
api_year as school_year, | ||
unioned.* | ||
{{ extract_extension(model_name=[this.name, 'stg_ef3__student_parent_associations'], flatten=True) }} | ||
from unioned | ||
), | ||
deduped as ( | ||
{{ | ||
dbt_utils.deduplicate( | ||
relation='keyed', | ||
partition_by='k_student, k_contact', | ||
order_by='pull_timestamp desc' | ||
) | ||
}} | ||
) | ||
select * from deduped |
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