Skip to content

Commit

Permalink
Modified dim_calendar_date.sql to support custom data sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
smckee-tnedu committed Oct 10, 2024
1 parent b9acae3 commit d0d872c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions models/core_warehouse/dim_calendar_date.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
]
)
}}
{# Load custom data sources from var #}
{% set custom_data_sources = var("edu:calendar_date:custom_data_sources", []) %}

with stg_calendar_date as (
select * from {{ ref('stg_ef3__calendar_dates') }}
Expand Down Expand Up @@ -79,7 +81,7 @@ week_offset as (
),
week_calculation as (
select
k_calendar_date,
augmented.k_calendar_date,
augmented.k_school_calendar,
k_school,
tenant_code,
Expand All @@ -101,10 +103,25 @@ week_calculation as (
then week_of_calendar_year - start_week_offset
else week_of_calendar_year + 52 - start_week_offset
end as week_of_school_year

-- custom indicators
{% if custom_data_sources is not none and custom_data_sources | length -%}
{%- for source in custom_data_sources -%}
{%- for indicator in custom_data_sources[source] -%}
, {{ custom_data_sources[source][indicator]['where'] }} as {{ indicator }}
{%- endfor -%}
{%- endfor -%}
{%- endif %}
from augmented
join week_offset
on augmented.k_school_calendar = week_offset.k_school_calendar

-- custom data sources
{% if custom_data_sources is not none and custom_data_sources | length -%}
{%- for source in custom_data_sources -%}
left join {{ ref(source) }}
on augmented.k_calendar_date = {{ source }}.k_calendar_date
{% endfor %}
{%- endif %}
)
select * from week_calculation
order by tenant_code, k_school, calendar_date desc

0 comments on commit d0d872c

Please sign in to comment.