Skip to content
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

fct_stu_contact_information #115

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions models/build/edfi_3/students/_edfi_3__students.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,18 @@ models:
- name: bld_ef3__wide_ids_student
config:
tags: ['core']
- name: bld_ef3__student_wide_addresses
config:
tags: ['core']
- name: bld_ef3__student_wide_emails
config:
tags: ['core']
- name: bld_ef3__student_wide_languages
config:
tags: ['core']
- name: bld_ef3__student_wide_phone_numbers
config:
tags: ['core']



22 changes: 22 additions & 0 deletions models/build/edfi_3/students/bld_ef3__student_wide_addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with stg_student_address as (
select * from {{ ref('stg_ef3__stu_ed_org__addresses') }}
),
address_wide as (
select
k_student,
tenant_code
{%- if not is_empty_model('stg_ef3__stu_ed_org__addresses') -%},
{{ dbt_utils.pivot(
'address_type',
dbt_utils.get_column_values(ref('stg_ef3__stu_ed_org__addresses'), 'address_type', order_by = 'address_type'),
agg='max',
then_value='street_address',
else_value='null',
suffix='_address',
quote_identifiers = False
) }}
{%- endif %}
from stg_student_address
group by k_student, tenant_code
)
select * from address_wide
22 changes: 22 additions & 0 deletions models/build/edfi_3/students/bld_ef3__student_wide_emails.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with stg_student_emails as (
select * from {{ ref('stg_ef3__stu_ed_org__emails') }}
),
email_wide as (
select
k_student,
tenant_code
{%- if not is_empty_model('stg_ef3__stu_ed_org__emails') -%},
{{ dbt_utils.pivot(
'email_type',
dbt_utils.get_column_values(ref('stg_ef3__stu_ed_org__emails'), 'email_type', order_by = 'email_type'),
agg='max',
then_value='email_address',
else_value='null',
suffix='_email_address',
quote_identifiers = False
) }}
{%- endif %}
from stg_student_emails
group by k_student, tenant_code
)
select * from email_wide
21 changes: 21 additions & 0 deletions models/build/edfi_3/students/bld_ef3__student_wide_languages.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
with stg_student_languages as (
select * from {{ ref('stg_ef3__stu_ed_org__languages') }}
),
language_wide as (
select
k_student,
tenant_code
{%- if not is_empty_model('stg_ef3__stu_ed_org__languages') -%},
{{ dbt_utils.pivot(
'language_use',
dbt_utils.get_column_values(ref('stg_ef3__stu_ed_org__languages'), 'language_use', order_by = 'language_use'),
agg='max',
then_value='code_value',
else_value='null',
quote_identifiers = False
) }}
{%- endif %}
from stg_student_languages
group by k_student, tenant_code
)
select * from language_wide
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with stg_student_phones as (
select * from {{ ref('stg_ef3__stu_ed_org__telephones') }}
),
phones_wide as (
select
k_student,
tenant_code
{%- if not is_empty_model('stg_ef3__stu_ed_org__telephones') -%},
{{ dbt_utils.pivot(
'phone_number_type',
dbt_utils.get_column_values(ref('stg_ef3__stu_ed_org__telephones'), 'phone_number_type', order_by = 'phone_number_type'),
agg='max',
then_value='phone_number',
else_value='null',
suffix='_phone_number',
quote_identifiers = False
) }}
{%- endif %}
from stg_student_phones
group by k_student, tenant_code
)
select * from phones_wide
18 changes: 15 additions & 3 deletions models/core_warehouse/dim_student.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
{% set custom_language_instruction_program_agg_indicators = var('edu:language_instruction:custom_program_agg_indicators', None) %}
{% set custom_title_i_program_agg_indicators = var('edu:title_i:custom_program_agg_indicators', None) %}


{# Load customizable column name for language use, defaults as home_language #}
{% set language_use_types = var('edu:stu_demos:language_use_types', None) %}

with stg_student as (
select * from {{ ref('stg_ef3__students') }}
),
Expand All @@ -49,7 +51,9 @@ stu_programs as (
stu_grade as (
select * from {{ ref('bld_ef3__stu_grade_level') }}
),

stu_language as (
select * from {{ ref('bld_ef3__student_wide_languages')}}
),
-- student programs
{% if var('src:program:special_ed:enabled', True) %}
stu_special_ed as (
Expand Down Expand Up @@ -184,12 +188,18 @@ formatted as (
{%- endfor -%}
{%- endif %}

-- student languages
{% if language_use_types is not none and language_use_types | length -%}
{%- for language_use in language_use_types -%}
stu_language.{{ language_use }},
{%- endfor -%}
{%- endif %}

-- add indicator of most recent demographic entry
stg_student.api_year = max(stg_student.api_year) over(partition by stg_student.k_student_xyear) as is_latest_record,

stu_immutable_demos.race_array,
stu_immutable_demos.safe_display_name

from stg_student

join stu_demos
Expand All @@ -212,6 +222,8 @@ formatted as (
left join stu_grade
on stu_demos.k_student = stu_grade.k_student
and stg_student.api_year = stu_grade.school_year
left join stu_language
on stg_student.k_student = stu_language.k_student

-- student programs
{% if var('src:program:special_ed:enabled', True) %}
Expand Down
6 changes: 5 additions & 1 deletion models/core_warehouse/dim_subgroup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
tags=['bypass_rls']
)
}}

{# bring in the customizable column name for language use from dim_student, defaults as home_language #}
{% set language_use_types = var('edu:stu_language:language_use_types', []) %}

with dim_student as (
select * from {{ ref('dim_student') }}
),
Expand Down Expand Up @@ -33,7 +37,7 @@ stu_long_subgroup as (
'birth_date',
'race_array',
'safe_display_name'
],
] + language_use_types,
remove = stu_id_cols,
field_name='subgroup_category',
value_name='subgroup_value'
Expand Down
67 changes: 67 additions & 0 deletions models/core_warehouse/fct_student_contact_information.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{# configure address preferred #}
{% set preferred = 'Physical' %}


with stu_phone_wide as (
select * from {{ ref('bld_ef3__student_wide_phone_numbers') }}
),
stu_emails_wide as (
select * from {{ ref('bld_ef3__student_wide_emails') }}
),
stu_address_wide as (
select * from {{ ref('bld_ef3__student_wide_addresses') }}
),
stu_language_wide as (
select * from {{ ref('bld_ef3__student_wide_languages') }}
),
dim_student as (
select * from {{ ref('dim_student') }}
),
choose_address as (
{{ row_pluck(ref('stg_ef3__stu_ed_org__addresses'),
key='k_student',
column='address_type',
preferred=preferred,
where='address_end_date is null') }}
)
select
dim_student.k_student,
dim_student.k_student_xyear,
dim_student.tenant_code,
dim_student.school_year,
{{ accordion_columns(
source_table='bld_ef3__student_wide_phone_numbers',
exclude_columns=["k_student", "tenant_code"],
source_alias='stu_phone_wide'
) }}
{{ accordion_columns(
source_table='bld_ef3__student_wide_emails',
exclude_columns=["k_student", "tenant_code"],
source_alias='stu_emails_wide'
) }}
{{ accordion_columns(
source_table='bld_ef3__student_wide_languages',
exclude_columns=["k_student", "tenant_code"],
source_alias='stu_language_wide'
) }}
{{ accordion_columns(
source_table='bld_ef3__student_wide_addresses',
exclude_columns=["k_student", "tenant_code"],
source_alias='stu_address_wide'
) }}
choose_address.city as {{preferred}}_address_city,
choose_address.name_of_county as {{preferred}}_address_name_of_county,
choose_address.state_code as {{preferred}}_address_state_code,
choose_address.postal_code as {{preferred}}_address_postal_code,
choose_address.building_site_number as {{preferred}}_address_building_site_number,
choose_address.locale as {{preferred}}_address_locale,
choose_address.congressional_district as {{preferred}}_address_congressional_district,
choose_address.county_fips_code as {{preferred}}_address_county_fips_code,
choose_address.latitude as {{preferred}}_address_latitude,
choose_address.longitude as {{preferred}}_address_longitude
from dim_student
left join stu_phone_wide on dim_student.k_student = stu_phone_wide.k_student
left join stu_emails_wide on dim_student.k_student = stu_emails_wide.k_student
left join stu_language_wide on dim_student.k_student = stu_language_wide.k_student
left join stu_address_wide on dim_student.k_student = stu_address_wide.k_student
left join choose_address on stu_address_wide.k_student = choose_address.k_student
22 changes: 22 additions & 0 deletions models/core_warehouse/fct_student_contact_information.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2

models:
- name: fct_student_contact_information
description: >
##### Overview:
Student contact information, including address, email, phone, and language.

##### Primary Key:
`k_student`

config:
tags: ['core']
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- k_student
columns:
- name: k_student
- name: k_student_xyear
- name: tenant_code
- name: school_year
5 changes: 4 additions & 1 deletion models/core_warehouse/fct_student_subgroup.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{# bring in the customizable column name for language use from dim_student, defaults as home_language #}
{% set language_use_types = var('edu:stu_language:language_use_types', []) %}

with dim_student as (
select * from {{ ref('dim_student') }}
),
Expand Down Expand Up @@ -25,7 +28,7 @@ stu_long_subgroup as (
'birth_date',
'race_array',
'safe_display_name'
],
] + language_use_types,
remove = stu_id_cols,
field_name='subgroup_category',
value_name='subgroup_value'
Expand Down