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

Modified dim_calendar_date to accept custom data sources. #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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