From 51025a4cbe5f3b172921be08aa0be84da9b41b24 Mon Sep 17 00:00:00 2001 From: cdelabre-pass <103637148+cdelabre-pass@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:29:24 +0100 Subject: [PATCH] (DE-1027) feat(dbt): update user_penetration legacy (#3759) --- .../analytics/enriched/user_penetration.sql | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/orchestration/dags/data_gcp_dbt/models/analytics/enriched/user_penetration.sql b/orchestration/dags/data_gcp_dbt/models/analytics/enriched/user_penetration.sql index c82164087f..1d5a0a01ba 100644 --- a/orchestration/dags/data_gcp_dbt/models/analytics/enriched/user_penetration.sql +++ b/orchestration/dags/data_gcp_dbt/models/analytics/enriched/user_penetration.sql @@ -1,35 +1,46 @@ --- temporary fix for CI, query unable to be run as view +-- Temporary fix for CI, query unable to be run as view {{ config(tags="failing_ci") }} with + -- Population data aggregated by department population_dpt as ( select - date(pop.current_date) active_month, pop.decimal_age, - date(pop.born_date) as born_date, pop.department_code, pop.department_name, dep.region_name, - sum(population) as population - from {{ source("seed", "population_age_and_department_france_details") }} pop + date(pop.current_date) as active_month, + date(pop.born_date) as born_date, + sum(pop.population) as population + from {{ source("seed", "population_age_and_department_france_details") }} as pop left join - {{ source("seed", "region_department") }} dep - on dep.num_dep = pop.department_code + {{ source("seed", "region_department") }} as dep + on pop.department_code = dep.num_dep where - pop.current_year in (2020, 2021, 2022, 2023, 2024) - and cast(age as int) between 15 and 25 - group by 1, 2, 3, 4, 5, 6 + pop.current_year in (2020, 2021, 2022, 2023, 2024, 2025) + and cast(pop.age as int) between 15 and 25 + group by + date(pop.current_date), + date(pop.born_date), + pop.decimal_age, + pop.department_code, + pop.department_name, + dep.region_name ), + -- User booking activity aggregated by department user_booking as ( select aa.active_month, aa.user_department_code as department_code, - date(date_trunc(ud.user_birth_date, month)) as born_date, + date(date_trunc(ud.user_birth_date, 'month')) as born_date, count(distinct ud.user_id) as total_users - from {{ ref("aggregated_monthly_user_used_booking_activity") }} aa - inner join {{ ref("mrt_global__user") }} ud on ud.user_id = aa.user_id - group by 1, 2, 3 + from {{ ref("aggregated_monthly_user_used_booking_activity") }} as aa + inner join {{ ref("mrt_global__user") }} as ud on aa.user_id = ud.user_id + group by + aa.active_month, + aa.user_department_code, + date(date_trunc(ud.user_birth_date, 'month')) ) select @@ -37,18 +48,19 @@ select pop.born_date, pop.decimal_age, pop.department_code, + coalesce(pop.population, 0) as population, coalesce(ub.total_users, 0) as total_users, case when pop.decimal_age >= 15 and pop.decimal_age < 18 - then "15_17" + then '15_17' when pop.decimal_age >= 18 and pop.decimal_age < 20 - then "18_19" - else "20_25" - end as age_range, - coalesce(population, 0) as population -from population_dpt pop + then '18_19' + else '20_25' + end as age_range +from population_dpt as pop left join - user_booking ub + user_booking as ub on pop.active_month = ub.active_month and pop.born_date = ub.born_date and pop.department_code = ub.department_code +;