From 45514dcd6a1568f27d167fc7a16e6a502333e372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Roqu=C3=A9=20Paniagua?= Date: Thu, 17 Apr 2025 10:01:15 +0000 Subject: [PATCH] Merged PR 5012: Small refactor on Growth Score # Description Small refactor on Growth Score model. It just handles the dimension deals attributes at the end instead of having these in each CTE. I also forced a partition ordered by deal AFTER the current ordering. This is a side effect because SQL randomly choses a value if the value being used to order was exactly the same (ex: revenue = 0). This was causing issues when auditing the refactor. # 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. Related work items: #29374 --- .../int_monthly_growth_score_by_deal.sql | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/models/intermediate/cross/int_monthly_growth_score_by_deal.sql b/models/intermediate/cross/int_monthly_growth_score_by_deal.sql index 3a87dd0..fd530f4 100644 --- a/models/intermediate/cross/int_monthly_growth_score_by_deal.sql +++ b/models/intermediate/cross/int_monthly_growth_score_by_deal.sql @@ -37,13 +37,7 @@ with d.month, d.date, date_trunc('month', d.date)::date as first_day_month, - -- DEAL STATIC ATTRIBUTES -- - ikdd.id_deal, - ikdd.client_type, - ikdd.main_deal_name, - ikdd.has_active_pms, - ikdd.active_pms_list, - ikdd.main_billing_country_iso_3_per_deal, + d.dimension_value as id_deal, -- DEAL LIFECYCLE -- deal_lifecycle.deal_lifecycle_state, -- METRICS -- @@ -53,7 +47,6 @@ with coalesce(created_bookings.created_bookings, 0) as created_bookings, coalesce(listings.listings_booked_in_month, 0) as listings_booked_in_month from int_kpis__agg_dates_main_kpis d - left join int_kpis__dimension_deals ikdd on d.dimension_value = ikdd.id_deal left join int_kpis__lifecycle_daily_deal deal_lifecycle on d.date = deal_lifecycle.date @@ -95,14 +88,16 @@ with ) as effective_global_revenue_12_months_window, row_number() over ( partition by first_day_month - order by deal_created_bookings_12_months_window desc + order by deal_created_bookings_12_months_window desc, id_deal ) as deal_contribution_rank_to_global_created_bookings, row_number() over ( partition by first_day_month - order by deal_avg_listings_booked_in_month_12_months_window desc + order by + deal_avg_listings_booked_in_month_12_months_window desc, id_deal ) as deal_contribution_rank_to_global_avg_listings_booked_in_month, row_number() over ( - partition by first_day_month order by deal_revenue_12_months_window desc + partition by first_day_month + order by deal_revenue_12_months_window desc, id_deal ) as deal_contribution_rank_to_global_revenue from ( @@ -142,12 +137,7 @@ with given_month.date, given_month.id_deal, - -- Deal Attributes - given_month.client_type, - given_month.main_deal_name, - given_month.has_active_pms, - given_month.active_pms_list, - given_month.main_billing_country_iso_3_per_deal, + -- Deal Dynamic Attributes given_month.deal_lifecycle_state, -- Dates - For Information Purposes @@ -297,11 +287,6 @@ with m.date, m.id_deal, - m.client_type, - m.main_deal_name, - m.has_active_pms, - m.active_pms_list, - m.main_billing_country_iso_3_per_deal, m.deal_lifecycle_state, m.given_month_first_day_month, @@ -404,12 +389,17 @@ select gsc.date, gsc.id_deal, - gsc.client_type, - gsc.main_deal_name, - gsc.has_active_pms, - gsc.active_pms_list, - gsc.main_billing_country_iso_3_per_deal, + -- DEAL STATIC ATTRIBUTES -- + ikdd.client_type, + ikdd.main_deal_name, + ikdd.has_active_pms, + ikdd.active_pms_list, + ikdd.main_billing_country_iso_3_per_deal, + + -- DEAL LIFECYCLE -- gsc.deal_lifecycle_state, + + -- DEAL HUBSPOT ATTRIBUTES -- d.deal_hubspot_stage, d.account_manager, d.live_date_utc, @@ -481,4 +471,5 @@ select else 'UNSET' end as categorisation_weighted_avg_growth_score from growth_score_computation gsc +left join int_kpis__dimension_deals ikdd on gsc.id_deal = ikdd.id_deal left join int_hubspot__deal d on gsc.id_deal = d.id_deal