From 72c966631e17d21f5223e7b5bc286206c1a1551c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Roqu=C3=A9=20Paniagua?= Date: Thu, 12 Sep 2024 10:27:56 +0000 Subject: [PATCH] Merged PR 2824: Propagates Billing Country and Deal Name into int_dates_by_deal # Description Changes: * Adding `main_deal_name` and `main_billing_country_iso_3_per_deal` in `int_dates_by_deal` model. * Documents the 2 new fields. Also, ensures `main_deal_name` is not null * Removes `id_deal not null` condition since it's enforced on the inner join with `int_core__deal` # 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: #18911, #19083 --- models/intermediate/cross/int_dates_by_deal.sql | 12 +++++++----- models/intermediate/cross/schema.yml | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/models/intermediate/cross/int_dates_by_deal.sql b/models/intermediate/cross/int_dates_by_deal.sql index 08c74ee..a560da2 100644 --- a/models/intermediate/cross/int_dates_by_deal.sql +++ b/models/intermediate/cross/int_dates_by_deal.sql @@ -1,9 +1,9 @@ - {{ 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") }}) + int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}), + int_core__deal as (select * from {{ ref("int_core__deal") }}) select distinct d.year_number as year, @@ -11,16 +11,18 @@ select distinct d.day_of_month as day, d.date_day as date, u.id_deal, + deal.main_deal_name, + deal.main_billing_country_iso_3_per_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 +inner join int_core__deal deal on deal.id_deal = u.id_deal where - u.id_deal is not null -- include only up-to yesterday - and now()::date > d.date_day + now()::date > d.date_day and ( - -- keep all last day of the month + -- keep all last day of the month d.date_day = d.month_end_date -- keep yesterday or now()::date = d.date_day + 1 diff --git a/models/intermediate/cross/schema.yml b/models/intermediate/cross/schema.yml index 6da3486..79425ad 100644 --- a/models/intermediate/cross/schema.yml +++ b/models/intermediate/cross/schema.yml @@ -303,6 +303,19 @@ models: tests: - not_null + - name: main_deal_name + data_type: string + description: | + Main name for this ID deal. + tests: + - not_null + + - name: main_billing_country_iso_3_per_deal + data_type: string + description: | + ISO 3166-1 alpha-3 main country code in which the Deal is billed. + In some cases it's null. + - name: int_mtd_aggregated_metrics description: | The `int_mtd_aggregated_metrics` model aggregates multiple metrics on a year, month, and day basis.