Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
with sections as (
select * from {{ ref('stg_ef3__sections') }}
),
xwalk_section_characteristics as (
select * from {{ ref('xwalk_section_characteristics') }}
),
flattened as (
select
k_course_section,
{{ edu_edfi_source.extract_descriptor('section_chars.value:sectionCharacteristicDescriptor::string') }} as section_characteristic
from sections
{{ edu_edfi_source.json_flatten('v_section_characteristics', 'section_chars', outer=true) }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need the outer=true here? What would be the benefit of creating rows for course sections without characteristics for this model?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed. I'ts been awhile since I wrote this but I might have been thinking that I saw outer=true as sort of a standard you guys were doing for these things? So that maybe if you had to troubleshoot data in the table, you'd have all the rows to look at and not just the rows that contained useful data? I don't know, to be honest.

),
pivoted as (
select
k_course_section,
{{ edu_edfi_source.json_array_agg(
'section_characteristic',
order_by='section_characteristic',
is_terminal=True
) }} as section_characteristics_array
{%- if not is_empty_model('xwalk_section_characteristics') -%},
{{ ea_pivot(
column='indicator_name',
values=dbt_utils.get_column_values(ref('xwalk_section_characteristics'), 'indicator_name'),
cast='boolean',
) }}
{%- endif %}
from flattened
left outer join xwalk_section_characteristics

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small, picky thing, can we use left join instead? It's the standard for the repo even if it means the same thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can, yes. They mean the same but I've always used the word "outer" just because in my history in IT (I'm old) I've always trained junior developers and explicitly saying "outer" has been helpful in reducing confusion.

on flattened.section_characteristic = xwalk_section_characteristics.section_characteristic_descriptor
group by all
)
select *
from pivoted
20 changes: 17 additions & 3 deletions models/core_warehouse/dim_course_section.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ stg_ef3__sections as (
dim_course as (
select * from {{ ref('dim_course') }}
),
section_chars as (
course_level_chars as (
select * from {{ ref('bld_ef3__course_char__combined_wide') }}
),
section_chars as (
select * from {{ ref('bld_ef3__section__wide_section_characteristics') }}
),
joined as (
select
stg_ef3__sections.k_course_section,
Expand All @@ -47,14 +50,23 @@ joined as (
stg_ef3__sections.is_official_attendance_period,
stg_ef3__sections.sequence_of_course,

-- section characteristics
-- course level characteristics
{{ accordion_columns(
source_table='bld_ef3__course_char__combined_wide',
exclude_columns=['tenant_code', 'api_year', 'k_course', 'k_course_offering', 'k_course_section', 'course_level_characteristics_array'],
source_alias='course_level_chars',
coalesce_value = 'FALSE'
) }}
course_level_chars.course_level_characteristics_array,

-- section characteristics
{{ accordion_columns(
source_table='bld_ef3__section__wide_section_characteristics',
exclude_columns=['k_course_section', 'section_characteristics_array'],
source_alias='section_chars',
coalesce_value = 'FALSE'
) }}
section_chars.course_level_characteristics_array,
section_chars.section_characteristics_array,

stg_ef3__sections.educational_environment_type,
stg_ef3__sections.instruction_language,
Expand All @@ -79,6 +91,8 @@ joined as (
on stg_ef3__sections.k_course_offering = offering.k_course_offering
join dim_course
on offering.k_course = dim_course.k_course
left join course_level_chars
on stg_ef3__sections.k_course_section = course_level_chars.k_course_section
left join section_chars
on stg_ef3__sections.k_course_section = section_chars.k_course_section
-- custom data sources
Expand Down