data-dwh-dbt-project/models/intermediate/cross/int_dates_by_deal.sql
Oriol Roqué Paniagua 94bdc53adf Merged PR 2498: Materialise int_dates_mtd and int_dates_by_deal as table to improve performance
# Description

Materialise int_dates_mtd and int_dates_by_deal as tables. This should improve the run speed as seen in local by quite a bit, and hopefully provide a better starting point for adding new dimensionality on business kpis.

I also documented these 2 models, that were missing :)

# 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.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [] Check if a full-refresh is required after this PR is merged.

Related work items: #19514
2024-08-06 15:03:32 +00:00

27 lines
781 B
SQL

{{ config(materialized="table", unique_key=["date", "id_deal"]) }}
with
int_dates as (select * from {{ ref("int_dates") }}),
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }})
select distinct
d.year_number as year,
d.month_of_year as month,
d.day_of_month as day,
d.date_day as date,
u.id_deal,
d.month_start_date as first_day_month,
d.month_end_date as last_day_month
from int_core__unified_user u
inner join int_dates d on d.date_day >= u.created_date_utc
where
u.id_deal is not null
-- include only up-to yesterday
and now()::date > d.date_day
and (
-- keep all last day of the month
d.date_day = d.month_end_date
-- keep yesterday
or now()::date = d.date_day + 1
)