From e85de15d229c80938526358951cfedec6834d431 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 10 Jun 2025 13:58:50 +0200 Subject: [PATCH 1/5] data alert fix --- ..._core__accommodation_to_product_bundle.sql | 21 ++++------------- .../core/int_core__new_dash_user_overview.sql | 16 ++++++------- models/intermediate/core/schema.yml | 23 ++++++------------- ...ew_dash_accommodation_offered_services.sql | 12 +++++----- 4 files changed, 25 insertions(+), 47 deletions(-) diff --git a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql index 9448284..f9cae5e 100644 --- a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql +++ b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql @@ -12,23 +12,10 @@ select atpb.id_user_product_bundle, upb.id_user_host, upb.product_bundle_display_name as user_product_bundle_name, - atpb.starts_at_utc as original_starts_at_utc, - atpb.ends_at_utc as original_ends_at_utc, - /* - The following is to ensure that we cap the reporting to the - dates in which these product bundles could have been active. - For analysis and reporting purposes, it is encouraged to use - the effective fields (start_date and end_date) rather than the - backend ones (named as original_starts_at and original_ends_at). - */ - greatest( - date(atpb.starts_at_utc), upb.effective_start_date_utc - ) as effective_start_date_utc, - case - when atpb.has_no_end_date - then null - else greatest(date(atpb.ends_at_utc), upb.effective_end_date_utc) - end as effective_end_date_utc, + atpb.starts_at_utc, + atpb.ends_at_utc, + date(atpb.starts_at_utc) as starts_date_utc, + date(atpb.ends_at_utc) as ends_date_utc, atpb.has_no_end_date, upb.product_bundle_services, upb.is_custom_bundle, 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 df99db4..856640b 100644 --- a/models/intermediate/core/int_core__new_dash_user_overview.sql +++ b/models/intermediate/core/int_core__new_dash_user_overview.sql @@ -68,11 +68,11 @@ with count( distinct case when - atpb.effective_start_date_utc <= current_date - and coalesce( - atpb.effective_end_date_utc, {{ var("end_of_time") }} + atpb.starts_date_utc <= current_date + and ( + atpb.ends_date_utc >= current_date + or atpb.has_no_end_date = true ) - >= current_date then atpb.id_accommodation else null end @@ -80,11 +80,11 @@ with count( distinct case when - atpb.effective_start_date_utc <= current_date - and coalesce( - atpb.effective_end_date_utc, {{ var("end_of_time") }} + atpb.starts_date_utc <= current_date + and ( + atpb.ends_date_utc >= current_date + or atpb.has_no_end_date = true ) - >= current_date and atpb.user_product_bundle_name not in ({{ var("default_service") }}) then atpb.id_accommodation diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index a159ae3..f069b98 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -2183,42 +2183,33 @@ models: description: | The name of the Product Bundle. - - name: original_starts_at_utc + - name: starts_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was active for the first time, according to the Backend. - Keep in mind that this timestamp can be before the migration of the user, thus - effective_start_date_utc might be better for reporting and analysis purposes. data_tests: - not_null - - name: original_ends_at_utc + - name: ends_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was active for the last time, according to the Backend. If null it means that it's currently active. - Keep in mind that this timestamp can be before the migration of the user, thus - effective_end_date_utc might be better for reporting and analysis purposes. - - name: effective_start_date_utc + - name: starts_date_utc data_type: date description: | - Effective date of when this Product Bundle is assigned into an Accommodation was - active for the first time. - It takes into account the fact that a User needs to be migrated in order for - the Product Bundle to be active in the Accommodation. In case of doubt, use this date. + The date when this Product Bundle was first assigned to the Accommodation. data_tests: - not_null - - name: effective_end_date_utc + - name: ends_date_utc data_type: date description: | - Effective date of when this Product Bundle is assigned into an Accommodation was - active for the last time. If null it means that it's currently active. - It takes into account the fact that a User needs to be migrated in order for - the Product Bundle to be active in the Accommodation. In case of doubt, use this date. + The date when this Product Bundle was last active for the Accommodation. + If null, it means the Product Bundle is currently active. - name: has_no_end_date data_type: boolean 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 710ff9d..19e0f88 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 @@ -16,11 +16,11 @@ with select *, row_number() over ( - partition by id_accommodation, effective_start_date_utc + partition by id_accommodation, starts_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 + starts_date_utc desc, -- Prefers the latest effective start date + starts_at_utc desc, -- In case of ties, prefers the most recent original start + coalesce(ends_at_utc, {{ var("end_of_time") }}) desc ) as rn from {{ ref("int_core__accommodation_to_product_bundle") }} ) @@ -51,8 +51,8 @@ inner join inner join 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") }}) + and date >= ldb.starts_date_utc + and (date < ldb.ends_date_utc or ldb.has_no_end_date = true) and ldb.rn = 1 left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas From a543fa1d83adb02e7cf9bb93c27b76c5156aa1a6 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 10 Jun 2025 14:20:28 +0200 Subject: [PATCH 2/5] changed names --- .../int_core__accommodation_to_product_bundle.sql | 8 ++++---- .../core/int_core__new_dash_user_overview.sql | 8 ++++---- models/intermediate/core/schema.yml | 8 ++++---- ...daily_new_dash_accommodation_offered_services.sql | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql index f9cae5e..afb967d 100644 --- a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql +++ b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql @@ -12,10 +12,10 @@ select atpb.id_user_product_bundle, upb.id_user_host, upb.product_bundle_display_name as user_product_bundle_name, - atpb.starts_at_utc, - atpb.ends_at_utc, - date(atpb.starts_at_utc) as starts_date_utc, - date(atpb.ends_at_utc) as ends_date_utc, + atpb.starts_at_utc as start_at_utc, + atpb.ends_at_utc as end_at_utc, + date(atpb.starts_at_utc) as start_date_utc, + date(atpb.ends_at_utc) as end_date_utc, atpb.has_no_end_date, upb.product_bundle_services, upb.is_custom_bundle, 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 856640b..0fcbfc7 100644 --- a/models/intermediate/core/int_core__new_dash_user_overview.sql +++ b/models/intermediate/core/int_core__new_dash_user_overview.sql @@ -68,9 +68,9 @@ with count( distinct case when - atpb.starts_date_utc <= current_date + atpb.start_date_utc <= current_date and ( - atpb.ends_date_utc >= current_date + atpb.end_date_utc >= current_date or atpb.has_no_end_date = true ) then atpb.id_accommodation @@ -80,9 +80,9 @@ with count( distinct case when - atpb.starts_date_utc <= current_date + atpb.start_date_utc <= current_date and ( - atpb.ends_date_utc >= current_date + atpb.end_date_utc >= current_date or atpb.has_no_end_date = true ) and atpb.user_product_bundle_name diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index f069b98..ba08316 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -2183,7 +2183,7 @@ models: description: | The name of the Product Bundle. - - name: starts_at_utc + - name: start_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was @@ -2191,21 +2191,21 @@ models: data_tests: - not_null - - name: ends_at_utc + - name: end_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was active for the last time, according to the Backend. If null it means that it's currently active. - - name: starts_date_utc + - name: start_date_utc data_type: date description: | The date when this Product Bundle was first assigned to the Accommodation. data_tests: - not_null - - name: ends_date_utc + - name: end_date_utc data_type: date description: | The date when this Product Bundle was last active for the Accommodation. 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 19e0f88..6b2792b 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 @@ -16,11 +16,11 @@ with select *, row_number() over ( - partition by id_accommodation, starts_date_utc + partition by id_accommodation, start_date_utc order by - starts_date_utc desc, -- Prefers the latest effective start date - starts_at_utc desc, -- In case of ties, prefers the most recent original start - coalesce(ends_at_utc, {{ var("end_of_time") }}) desc + start_date_utc desc, -- Prefers the latest effective start date + start_at_utc desc, -- In case of ties, prefers the most recent original start + coalesce(end_at_utc, {{ var("end_of_time") }}) desc ) as rn from {{ ref("int_core__accommodation_to_product_bundle") }} ) @@ -51,8 +51,8 @@ inner join inner join latest_daily_bundle as ldb on bs.id_user_product_bundle = ldb.id_user_product_bundle - and date >= ldb.starts_date_utc - and (date < ldb.ends_date_utc or ldb.has_no_end_date = true) + and date >= ldb.start_date_utc + and (date < ldb.end_date_utc or ldb.has_no_end_date = true) and ldb.rn = 1 left join {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas From 1bd2fd9585c73af1c4e369d661ae672dc720d73b Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 10 Jun 2025 14:22:40 +0200 Subject: [PATCH 3/5] updated comments --- ...__metric_daily_new_dash_accommodation_offered_services.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 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 6b2792b..395ec5f 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 @@ -18,8 +18,8 @@ with row_number() over ( partition by id_accommodation, start_date_utc order by - start_date_utc desc, -- Prefers the latest effective start date - start_at_utc desc, -- In case of ties, prefers the most recent original start + start_date_utc desc, -- Prefers the latest starting date + start_at_utc desc, -- In case of ties, prefers the most recent starting time coalesce(end_at_utc, {{ var("end_of_time") }}) desc ) as rn from {{ ref("int_core__accommodation_to_product_bundle") }} From c5c25af59bcac434dd26d4e315ef308b719beafa Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 10 Jun 2025 14:42:59 +0200 Subject: [PATCH 4/5] addressed comments --- .../core/int_core__accommodation_to_product_bundle.sql | 4 ++-- models/intermediate/core/schema.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql index afb967d..3b262f6 100644 --- a/models/intermediate/core/int_core__accommodation_to_product_bundle.sql +++ b/models/intermediate/core/int_core__accommodation_to_product_bundle.sql @@ -12,8 +12,8 @@ select atpb.id_user_product_bundle, upb.id_user_host, upb.product_bundle_display_name as user_product_bundle_name, - atpb.starts_at_utc as start_at_utc, - atpb.ends_at_utc as end_at_utc, + atpb.starts_at_utc, + atpb.ends_at_utc, date(atpb.starts_at_utc) as start_date_utc, date(atpb.ends_at_utc) as end_date_utc, atpb.has_no_end_date, diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index ba08316..6211fda 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -2183,7 +2183,7 @@ models: description: | The name of the Product Bundle. - - name: start_at_utc + - name: starts_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was @@ -2191,7 +2191,7 @@ models: data_tests: - not_null - - name: end_at_utc + - name: ends_at_utc data_type: timestamp description: | Timestamp of when this Product Bundle is assigned into an Accommodation was From 5f2bd33eeddee81b8c5333d17346ff025d9e2223 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Tue, 10 Jun 2025 14:45:53 +0200 Subject: [PATCH 5/5] addressed comments --- ...__metric_daily_new_dash_accommodation_offered_services.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 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 395ec5f..a4a9d5e 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 @@ -19,8 +19,8 @@ with partition by id_accommodation, start_date_utc order by start_date_utc desc, -- Prefers the latest starting date - start_at_utc desc, -- In case of ties, prefers the most recent starting time - coalesce(end_at_utc, {{ var("end_of_time") }}) desc + starts_at_utc desc, -- In case of ties, prefers the most recent starting time + coalesce(ends_at_utc, {{ var("end_of_time") }}) desc ) as rn from {{ ref("int_core__accommodation_to_product_bundle") }} )