From 525c12dc831b30226ec54bdbcc6f11ff0de324f5 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 25 Mar 2025 16:47:26 +0100 Subject: [PATCH 1/4] Commit wip --- ...ew_dash_accommodation_offered_services.sql | 44 ++++++++ models/intermediate/kpis/schema.yml | 102 ++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql new file mode 100644 index 0000000..2f1c292 --- /dev/null +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql @@ -0,0 +1,44 @@ +{{ + config( + materialized="table", + unique_key=[ + "date", + "id_accommodation", + "id_user_product_bundle", + "service_name", + "service_business_type", + ], + ) +}} +select + -- Unique Key -- + dd.date, + apb.id_accommodation, + bs.id_user_product_bundle, + bs.service_name, + bs.service_business_type, + -- Dimensions -- + coalesce(uh.id_deal, 'UNSET') as id_deal, + case when bs.is_default_service then 'NO' else 'YES' end as is_upgraded_service, + coalesce(uh.new_dash_version, 'UNSET') as new_dash_version, + coalesce( + uh.main_billing_country_iso_3_per_deal, 'UNSET' + ) as main_billing_country_iso_3_per_deal, + coalesce( + icmas.active_accommodations_per_deal_segmentation, 'UNSET' + ) as active_accommodations_per_deal_segmentation +from {{ ref("int_kpis__dimension_dates") }} as dd +inner join + {{ ref("int_core__user_host") }} as uh + on dd.date >= uh.user_in_new_dash_since_date_utc +inner join + {{ ref("int_core__user_product_bundle_contains_services") }} as bs + on uh.id_user_host = bs.id_user_host +inner join + {{ ref("int_core__accommodation_to_product_bundle") }} as apb + on bs.id_user_product_bundle = apb.id_user_product_bundle + and date between apb.effective_start_date_utc and apb.effective_end_date_utc +left join + {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas + on uh.id_deal = icmas.id_deal + and dd.date = icmas.date diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index 0cd1468..82f7495 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -7482,6 +7482,108 @@ models: - "61+" - "UNSET" + - name: main_billing_country_iso_3_per_deal + data_type: string + description: | + Main billing country of the host aggregated at Deal level. + data_tests: + - not_null + + - name: int_kpis__metric_daily_new_dash_accommodation_offered_services + description: | + This model computes the Daily Offered Services by Listings at the deepest granularity. + It only retrieves services that come from users that are in New Dash, as well + as it only considers services created after the user has moved to New Dash. + The unique key corresponds to the deepest granularity of the model, + in this case: + - date, + - id_accommodation, + - id_user_product_bundle, + - service_name, + - service_business_type + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - date + - id_accommodation + - id_user_product_bundle + - service_name + - service_business_type + columns: + - name: date + data_type: date + description: Date of when user has a bundle with service active. + data_tests: + - not_null + - name: id_accommodation + data_type: bigint + description: Unique identifier of an accommodation, or listing. + data_tests: + - not_null + - name: id_user_product_bundle + data_type: bigint + description: Unique identifier of the User Product Bundle. + data_tests: + - not_null + - name: service_name + data_type: string + description: Name of the created service. + data_tests: + - not_null + - name: service_business_type + data_type: string + description: | + Identifies the service type (Screening, Deposit Management, Protection + or Guest Agreement) according to New Pricing documentation. + Cannot be null. + data_tests: + - not_null + - accepted_values: + values: + - "SCREENING" + - "PROTECTION" + - "DEPOSIT_MANAGEMENT" + - "GUEST_AGREEMENT" + - "UNKNOWN" + - "UNSET" + - name: id_deal + data_type: string + description: Unique identifier of an account. + data_tests: + - not_null + - name: is_upgraded_service + data_type: string + description: | + Whether the service is an upgraded version of the + default. In other words, if it's not Basic Screening. + data_tests: + - not_null + - accepted_values: + values: + - "YES" + - "NO" + - name: new_dash_version + data_type: string + description: | + The version of the New Dash. It corresponds to the + release or migration phase from user point of view. + data_tests: + - not_null + - name: active_accommodations_per_deal_segmentation + data_type: string + description: | + Segment value based on the number of listings booked in 12 months + for a given deal and date. + data_tests: + - not_null + - accepted_values: + values: + - "0" + - "01-05" + - "06-20" + - "21-60" + - "61+" + - "UNSET" - name: main_billing_country_iso_3_per_deal data_type: string description: | From 87517f6a92249f1ba255257a5792c5594d530514 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 26 Mar 2025 08:41:51 +0100 Subject: [PATCH 2/4] Listings offered services --- ...__metric_daily_new_dash_accommodation_offered_services.sql | 4 +++- models/intermediate/kpis/schema.yml | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql index 2f1c292..bde0477 100644 --- a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql @@ -37,7 +37,9 @@ inner join inner join {{ ref("int_core__accommodation_to_product_bundle") }} as apb on bs.id_user_product_bundle = apb.id_user_product_bundle - and date between apb.effective_start_date_utc and apb.effective_end_date_utc + and date between apb.effective_start_date_utc and coalesce( + apb.effective_end_date_utc, {{ var("end_of_time") }} + ) left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas on uh.id_deal = icmas.id_deal diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index 82f7495..b0aee31 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -7544,8 +7544,6 @@ models: - "PROTECTION" - "DEPOSIT_MANAGEMENT" - "GUEST_AGREEMENT" - - "UNKNOWN" - - "UNSET" - name: id_deal data_type: string description: Unique identifier of an account. From 3f082292568c88205b60a9eb6e503e7f7c956247 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 26 Mar 2025 17:01:23 +0100 Subject: [PATCH 3/4] New Dash Listings with services --- ...ew_dash_accommodation_offered_services.sql | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql index bde0477..c1ecc09 100644 --- a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql @@ -10,10 +10,21 @@ ], ) }} +with + -- Selects the most recent product bundle per accommodation per day + latest_daily_bundle as ( + select distinct on (id_accommodation, effective_start_date_utc) * + from {{ ref("int_core__accommodation_to_product_bundle") }} + order by + id_accommodation, -- Ensures we are filtering per accommodation + effective_start_date_utc desc, -- Prefers the latest effective start date + original_starts_at_utc desc, -- In case of ties, prefers the most recent original start + coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc + ) select -- Unique Key -- dd.date, - apb.id_accommodation, + ldb.id_accommodation, bs.id_user_product_bundle, bs.service_name, bs.service_business_type, @@ -35,11 +46,10 @@ inner join {{ ref("int_core__user_product_bundle_contains_services") }} as bs on uh.id_user_host = bs.id_user_host inner join - {{ ref("int_core__accommodation_to_product_bundle") }} as apb - on bs.id_user_product_bundle = apb.id_user_product_bundle - and date between apb.effective_start_date_utc and coalesce( - apb.effective_end_date_utc, {{ var("end_of_time") }} - ) + latest_daily_bundle as ldb + on bs.id_user_product_bundle = ldb.id_user_product_bundle + and date >= ldb.effective_start_date_utc + and date < coalesce(ldb.effective_end_date_utc, {{ var("end_of_time") }}) left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas on uh.id_deal = icmas.id_deal From c60bfc6ccb6d9e23439ff8c95f7339da43de2bc8 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Thu, 27 Mar 2025 11:24:17 +0100 Subject: [PATCH 4/4] Addressed comments --- ...new_dash_accommodation_offered_services.sql | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql index c1ecc09..710ff9d 100644 --- a/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql +++ b/models/intermediate/kpis/int_kpis__metric_daily_new_dash_accommodation_offered_services.sql @@ -11,15 +11,18 @@ ) }} with - -- Selects the most recent product bundle per accommodation per day + -- Order by the most recent product bundle per accommodation per day latest_daily_bundle as ( - select distinct on (id_accommodation, effective_start_date_utc) * + select + *, + row_number() over ( + partition by id_accommodation, effective_start_date_utc + order by + effective_start_date_utc desc, -- Prefers the latest effective start date + original_starts_at_utc desc, -- In case of ties, prefers the most recent original start + coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc + ) as rn from {{ ref("int_core__accommodation_to_product_bundle") }} - order by - id_accommodation, -- Ensures we are filtering per accommodation - effective_start_date_utc desc, -- Prefers the latest effective start date - original_starts_at_utc desc, -- In case of ties, prefers the most recent original start - coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc ) select -- Unique Key -- @@ -50,6 +53,7 @@ inner join on bs.id_user_product_bundle = ldb.id_user_product_bundle and date >= ldb.effective_start_date_utc and date < coalesce(ldb.effective_end_date_utc, {{ var("end_of_time") }}) + and ldb.rn = 1 left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas on uh.id_deal = icmas.id_deal