Merged PR 3427: Weekly dimension
# Description Added week values to the kpis__dimension_dates model for weekly aggregations # Checklist - [x] The edited models and dependants run properly with production data. - [x] The edited models are sufficiently documented. - [x] The edited models contain PK tests, and I've ran and passed them. - [ ] I have checked for DRY opportunities with other models and docs. - [ ] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. Weekly dimension
This commit is contained in:
commit
76529fe457
2 changed files with 46 additions and 1 deletions
|
|
@ -8,16 +8,20 @@ with
|
||||||
select
|
select
|
||||||
id.year_number as year,
|
id.year_number as year,
|
||||||
id.month_of_year as month,
|
id.month_of_year as month,
|
||||||
|
id.week_of_year as week,
|
||||||
id.day_of_month as day,
|
id.day_of_month as day,
|
||||||
id.date_day as date,
|
id.date_day as date,
|
||||||
id.month_start_date as first_day_month,
|
id.month_start_date as first_day_month,
|
||||||
id.month_end_date as last_day_month,
|
id.month_end_date as last_day_month,
|
||||||
|
id.week_start_date as first_day_week,
|
||||||
|
id.week_end_date as last_day_week,
|
||||||
now()::date as today
|
now()::date as today
|
||||||
from int_dates id
|
from int_dates id
|
||||||
)
|
)
|
||||||
select distinct
|
select distinct
|
||||||
rd.year,
|
rd.year,
|
||||||
rd.month,
|
rd.month,
|
||||||
|
rd.week,
|
||||||
rd.day,
|
rd.day,
|
||||||
rd.date,
|
rd.date,
|
||||||
rd.first_day_month,
|
rd.first_day_month,
|
||||||
|
|
@ -37,7 +41,15 @@ select distinct
|
||||||
and rd.day < extract(day from rd.today)
|
and rd.day < extract(day from rd.today)
|
||||||
then true
|
then true
|
||||||
else false
|
else false
|
||||||
end as is_month_to_date
|
end as is_month_to_date,
|
||||||
|
rd.first_day_week,
|
||||||
|
rd.last_day_week,
|
||||||
|
case when rd.date = rd.last_day_week then true else false end as is_end_of_week,
|
||||||
|
case
|
||||||
|
when date_trunc('week', rd.date) = date_trunc('week', rd.today)
|
||||||
|
then true
|
||||||
|
else false
|
||||||
|
end as is_current_week
|
||||||
from raw_dates rd
|
from raw_dates rd
|
||||||
where
|
where
|
||||||
-- include only up-to yesterday
|
-- include only up-to yesterday
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@ models:
|
||||||
tests:
|
tests:
|
||||||
- not_null
|
- not_null
|
||||||
|
|
||||||
|
- name: week
|
||||||
|
data_type: int
|
||||||
|
description: Week number of the given date.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
- name: day
|
- name: day
|
||||||
data_type: int
|
data_type: int
|
||||||
description: Day monthly number of the given date.
|
description: Day monthly number of the given date.
|
||||||
|
|
@ -70,6 +76,33 @@ models:
|
||||||
tests:
|
tests:
|
||||||
- not_null
|
- not_null
|
||||||
|
|
||||||
|
- name: first_day_week
|
||||||
|
data_type: date
|
||||||
|
description: |
|
||||||
|
First day of the week corresponding to the date field.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: last_day_week
|
||||||
|
data_type: date
|
||||||
|
description: |
|
||||||
|
Last day of the week corresponding to the date field.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: is_end_of_week
|
||||||
|
data_type: boolean
|
||||||
|
description: True if it's end of week, false otherwise.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
|
- name: is_current_week
|
||||||
|
data_type: boolean
|
||||||
|
description: |
|
||||||
|
True if the date is within the current week, false otherwise.
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
|
||||||
- name: int_kpis__lifecycle_daily_accommodation
|
- name: int_kpis__lifecycle_daily_accommodation
|
||||||
description: |
|
description: |
|
||||||
This model computes the daily lifecycle segment for each accommodation, also known as
|
This model computes the daily lifecycle segment for each accommodation, also known as
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue