Merged PR 4117: Added PMS info

# Description

Added PMS info to `int_core__user_host` and propagated data to where needed

# 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.

Added PMS info

Related work items: #26589
This commit is contained in:
Joaquin Ossa 2025-01-21 08:07:22 +00:00
commit 90967fd34e
5 changed files with 96 additions and 26 deletions

View file

@ -2,6 +2,10 @@
with
int_core__unified_user as (select * from {{ ref("int_core__unified_user") }}),
int_core__country as (select * from {{ ref("int_core__country") }}),
stg_core__integration as (select * from {{ ref("stg_core__integration") }}),
stg_core__integration_type as (
select * from {{ ref("stg_core__integration_type") }}
),
-- A Deal can have multiple users, which in turn can have different
-- billing countries. We assume here that the main billing country
@ -70,6 +74,22 @@ with
from potential_name_per_deal
) as ranked_names
where rn = 1
),
-- 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_deal,
@ -78,11 +98,16 @@ select
mbcpd.main_billing_country_name_per_deal,
mbcpd.main_billing_country_iso_2_per_deal,
mbcpd.main_billing_country_iso_3_per_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,
count(distinct uu.id_user) as users_with_this_id_deal,
count(distinct uu.billing_country_iso_3) as billing_countries_for_this_id_deal,
min(uu.created_date_utc) as first_created_date_utc
from main_billing_country_per_deal mbcpd
left join int_core__unified_user uu on uu.id_deal = mbcpd.id_deal
left join unique_name_per_deal unpd on uu.id_deal = unpd.id_deal
left join integrations_per_deal ipd on uu.id_deal = ipd.id_deal
where mbcpd.id_deal is not null
group by 1, 2, 3, 4, 5, 6
group by 1, 2, 3, 4, 5, 6, 7, 8

View file

@ -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,

View file

@ -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 sci.id_superhog_user as id_user_host, 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_host as (
select
id_user_host, string_agg(distinct active_pms, ', ') as distinct_active_pms
from integrations_per_user
group by id_user_host
)
select
uu.id_user as id_user_host,
@ -43,6 +62,10 @@ select
uu.company_name,
uu.email,
uu.id_deal,
case
when iph.distinct_active_pms is null then false else true
end as has_active_pms,
iph.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_host iph on uu.id_user = iph.id_user_host

View file

@ -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 host 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 host. 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 host 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 host. 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: |
@ -2830,6 +2854,17 @@ models:
description: |
ISO 3166-1 alpha-3 main country code in which the Deal is billed.
In some cases it's 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: users_with_this_id_deal
data_type: integer
description: |

View file

@ -26,34 +26,19 @@ with
select
id_deal,
main_deal_name,
has_active_pms,
active_pms_list,
first_created_date_utc as deal_start_date,
date_trunc('month', first_created_date_utc) as deal_start_month,
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
),
combined_deals as (
select
coalesce(hd.id_deal, cd.id_deal) as id_deal,
coalesce(hd.main_deal_name, cd.main_deal_name) as main_deal_name,
coalesce(cd.has_active_pms, false) as has_active_pms,
cd.active_pms_list,
cd.main_billing_country_iso_3_per_deal,
min(
coalesce(hd.deal_start_date, cd.deal_start_date)
@ -66,15 +51,13 @@ with
min(hd.hubspot_listing_segmentation) as hubspot_listing_segmentation
from hubspot_deals hd
full outer join core_deals cd on hd.id_deal = cd.id_deal
group by 1, 2, 3
group by 1, 2, 3, 4, 5
)
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,
cd.has_active_pms,
cd.active_pms_list,
cd.main_billing_country_iso_3_per_deal,
cd.effective_deal_start_date_utc,
cd.effective_deal_start_month,
@ -82,4 +65,3 @@ select
cd.hubspot_deal_cancellation_month,
cd.hubspot_listing_segmentation
from combined_deals cd
left join integrations_per_deal ipd on cd.id_deal = ipd.id_deal