From 5c71791f10d5cf16a3b4b48fcb41caddc75cc5dd Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 20 Jan 2025 14:26:37 +0100 Subject: [PATCH] Added PMS info --- .../core/int_core__new_dash_user_overview.sql | 4 +++ .../intermediate/core/int_core__user_host.sql | 24 ++++++++++++++++++ models/intermediate/core/schema.yml | 24 ++++++++++++++++++ .../kpis/int_kpis__dimension_deals.sql | 25 +++---------------- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/models/intermediate/core/int_core__new_dash_user_overview.sql b/models/intermediate/core/int_core__new_dash_user_overview.sql index 3d446d3..97af86b 100644 --- a/models/intermediate/core/int_core__new_dash_user_overview.sql +++ b/models/intermediate/core/int_core__new_dash_user_overview.sql @@ -90,6 +90,8 @@ with uh.has_user_moved_from_old_dash, uh.new_dash_version as user_migration_phase, uh.user_in_new_dash_since_date_utc as user_estimated_migration_date_utc, + uh.has_active_pms, + uh.active_pms_list, uh.company_name, uh.first_name, uh.last_name, @@ -115,6 +117,8 @@ select has_user_moved_from_old_dash, user_migration_phase, user_estimated_migration_date_utc, + has_active_pms, + active_pms_list, company_name, first_name, last_name, diff --git a/models/intermediate/core/int_core__user_host.sql b/models/intermediate/core/int_core__user_host.sql index 1747041..fdcb346 100644 --- a/models/intermediate/core/int_core__user_host.sql +++ b/models/intermediate/core/int_core__user_host.sql @@ -9,6 +9,10 @@ with int_core__new_dash_users as (select * from {{ ref("int_core__new_dash_users") }}), stg_core__claim as (select * from {{ ref("stg_core__claim") }}), int_core__deal as (select * from {{ ref("int_core__deal") }}), + stg_core__integration as (select * from {{ ref("stg_core__integration") }}), + stg_core__integration_type as ( + select * from {{ ref("stg_core__integration_type") }} + ), -- A USER CAN HAVE MULTIPLE ROLES, THUS DISTINCT IS NEEDED TO AVOID DUPLICATES users_with_host_roles as ( @@ -27,6 +31,21 @@ with select coalesce(r.id_user, k.id_user) as id_user from users_with_host_roles r full outer join users_from_kyg k on r.id_user = k.id_user + ), + -- PMS INTEGRATIONS + integrations_per_user as ( + select + uu.id_deal, sci.id_superhog_user as id_user, scit.display_name as active_pms + from stg_core__integration sci + left join + stg_core__integration_type scit + on sci.id_integration_type = scit.id_integration_type + left join int_core__unified_user uu on sci.id_superhog_user = uu.id_user + ), + integrations_per_deal as ( + select id_deal, string_agg(distinct active_pms, ', ') as distinct_active_pms + from integrations_per_user + group by id_deal ) select uu.id_user as id_user_host, @@ -43,6 +62,10 @@ select uu.company_name, uu.email, uu.id_deal, + case + when ipd.distinct_active_pms is null then false else true + end as has_active_pms, + ipd.distinct_active_pms as active_pms_list, d.main_billing_country_name_per_deal, d.main_billing_country_iso_2_per_deal, d.main_billing_country_iso_3_per_deal, @@ -66,3 +89,4 @@ from int_core__unified_user uu inner join unique_host_user uhu on uu.id_user = uhu.id_user left join int_core__new_dash_users ndu on uu.id_user = ndu.id_user_host left join int_core__deal d on uu.id_deal = d.id_deal +left join integrations_per_deal ipd on uu.id_deal = ipd.id_deal diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 9c70633..a59c2f1 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -1945,6 +1945,17 @@ models: description: | Main identifier of the B2B clients. A Deal can have multiple Hosts. A Host can have only 1 Deal or no Deal at all. This field can be null. + - name: has_active_pms + data_type: boolean + description: | + Does the deal have an active associated PMS. + data_tests: + - not_null + - name: active_pms_list + data_type: string + description: | + Name of the active PMS associated with the deal. It can have more than + one PMS associated with it. It can be null if it doesn't have any PMS associated. - name: main_billing_country_name_per_deal data_type: string description: | @@ -2499,6 +2510,19 @@ models: data_tests: - not_null + - name: has_active_pms + data_type: boolean + description: | + Does the deal have an active associated PMS. + data_tests: + - not_null + + - name: active_pms_list + data_type: string + description: | + Name of the active PMS associated with the deal. It can have more than + one PMS associated with it. It can be null if it doesn't have any PMS associated. + - name: company_name data_type: string description: | diff --git a/models/intermediate/kpis/int_kpis__dimension_deals.sql b/models/intermediate/kpis/int_kpis__dimension_deals.sql index 4794e95..5399957 100644 --- a/models/intermediate/kpis/int_kpis__dimension_deals.sql +++ b/models/intermediate/kpis/int_kpis__dimension_deals.sql @@ -31,24 +31,9 @@ with main_billing_country_iso_3_per_deal from {{ ref("int_core__deal") }} ), - integrations_per_user as ( - select - icuh.id_deal, - sci.id_superhog_user as id_user, - scit.display_name as active_pms - from {{ ref("stg_core__integration") }} sci - left join - {{ ref("stg_core__integration_type") }} scit - on sci.id_integration_type = scit.id_integration_type - left join - {{ ref("int_core__user_host") }} icuh - on sci.id_superhog_user = icuh.id_user_host - where sci.is_active = true and icuh.is_missing_id_deal = false - ), integrations_per_deal as ( - select id_deal, string_agg(distinct active_pms, ', ') as distinct_active_pms - from integrations_per_user - group by id_deal + select distinct id_deal, has_active_pms, active_pms_list + from {{ ref("int_core__user_host") }} ), combined_deals as ( select @@ -71,10 +56,8 @@ with select cd.id_deal, cd.main_deal_name, - case - when ipd.distinct_active_pms is null then false else true - end as has_active_pms, - ipd.distinct_active_pms as active_pms_list, + coalesce(ipd.has_active_pms, false) as has_active_pms, + ipd.active_pms_list, cd.main_billing_country_iso_3_per_deal, cd.effective_deal_start_date_utc, cd.effective_deal_start_month,