From 34985f3de172660fd749f418c2ea5e931a1286e7 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 27 May 2025 15:01:47 +0200 Subject: [PATCH 1/5] wrap final select in cte --- .../core/int_core__vr_check_in_cover.sql | 182 +++++++++--------- 1 file changed, 96 insertions(+), 86 deletions(-) diff --git a/models/intermediate/core/int_core__vr_check_in_cover.sql b/models/intermediate/core/int_core__vr_check_in_cover.sql index 5abf059..d4f4ef4 100644 --- a/models/intermediate/core/int_core__vr_check_in_cover.sql +++ b/models/intermediate/core/int_core__vr_check_in_cover.sql @@ -22,90 +22,100 @@ with amount_without_taxes_in_gbp from {{ ref("int_core__guest_journey_payments") }} where product_name = 'CHECKINCOVER' and payment_status in ('PAID', 'REFUNDED') + ), + pre_feature_flag_verification_requests as ( + select + vr.id_verification_request, + vr.uuid_verification_request, + vr.id_verification_set, + vr.id_superhog_verified_set, + vr.id_payment_validation_set, + vr.id_user_guest, + vr.id_user_host, + b.id_booking, + b.id_accommodation, + vr.is_verification_request_complete, + ( + p.total_amount_in_txn_currency is not null + and not b.check_in_sits_in_future + ) as is_past_check_in, + ( + p.total_amount_in_txn_currency is not null + and b.check_in_sits_in_future + and vr.is_verification_request_complete + ) as is_awaiting_check_in, + p.total_amount_in_txn_currency is not null as cover_was_purchased, + ( + p.total_amount_in_txn_currency is null + and vr.is_verification_request_complete + ) as cover_was_rejected, + vr.verification_url, + vr.callback_url, + vr.redirect_url, + vr.logo, + gu.email as guest_email, + gu.last_name as last_name, + gu.first_name as first_name, + gu.phone_number as guest_phone_number, + vr.telephone_code, + vr.guest_phone_number_2, + b.check_in_at_utc, + b.check_in_date_utc, + b.check_out_at_utc, + b.check_out_date_utc, + vr.verification_estimated_started_at_utc as verification_start_at_utc, + vr.verification_estimated_started_date_utc as verification_start_date_utc, + vr.verification_estimated_completed_at_utc as verification_end_at_utc, + vr.verification_estimated_completed_date_utc as verification_end_date_utc, + vr.link_used_at_utc, + vr.link_used_date_utc, + vr.expire_at_utc, + vr.expire_date_utc, + vr.is_deleted, + vr.redirect_name, + vr.id_one_step_link, + vr.success_message, + vr.summary, + vr.rejection_reason, + vr.has_switched_to_mobile, + vr.is_verifier_rejected, + vr.config, + vr.metadata, + vr.created_at_utc, + vr.created_date_utc, + vr.updated_at_utc, + vr.updated_date_utc, + vr.dwh_extracted_at_utc, + p.currency, + p.payment_status, + p.payment_paid_date_utc, + p.total_amount_in_txn_currency, + p.amount_without_taxes_in_txn_currency, + p.total_amount_in_gbp, + p.amount_without_taxes_in_gbp, + ccp.checkin_cover_limit_amount_local_curr, + ( + ccp.checkin_cover_limit_amount_local_curr + * (p.total_amount_in_gbp / p.total_amount_in_txn_currency) + )::numeric(18, 4) as checkin_cover_limit_amount_in_gbp + from int_core__verification_requests vr + left join + int_core__bookings b + on vr.id_verification_request = b.id_verification_request + left join + stg_core__verification_set_to_verification_type vstvt + on vr.id_verification_set = vstvt.id_verification_set + left join + check_in_cover_payments p + on vr.id_verification_request = p.id_verification_request + left join + int_core__check_in_cover_prices ccp + on p.currency = ccp.local_currency_iso_4217 + left join int_core__unified_user gu on gu.id_user = vr.id_user_guest + -- 15 is Check-in cover. + -- Adding this condition results in only keeping guest journeys that offered the + -- check-in cover + where vstvt.id_verification_type = 15 ) -select - vr.id_verification_request, - vr.uuid_verification_request, - vr.id_verification_set, - vr.id_superhog_verified_set, - vr.id_payment_validation_set, - vr.id_user_guest, - vr.id_user_host, - b.id_booking, - b.id_accommodation, - vr.is_verification_request_complete, - ( - p.total_amount_in_txn_currency is not null and not b.check_in_sits_in_future - ) as is_past_check_in, - ( - p.total_amount_in_txn_currency is not null - and b.check_in_sits_in_future - and vr.is_verification_request_complete - ) as is_awaiting_check_in, - p.total_amount_in_txn_currency is not null as cover_was_purchased, - ( - p.total_amount_in_txn_currency is null and vr.is_verification_request_complete - ) as cover_was_rejected, - vr.verification_url, - vr.callback_url, - vr.redirect_url, - vr.logo, - gu.email as guest_email, - gu.last_name as last_name, - gu.first_name as first_name, - gu.phone_number as guest_phone_number, - vr.telephone_code, - vr.guest_phone_number_2, - b.check_in_at_utc, - b.check_in_date_utc, - b.check_out_at_utc, - b.check_out_date_utc, - vr.verification_estimated_started_at_utc as verification_start_at_utc, - vr.verification_estimated_started_date_utc as verification_start_date_utc, - vr.verification_estimated_completed_at_utc as verification_end_at_utc, - vr.verification_estimated_completed_date_utc as verification_end_date_utc, - vr.link_used_at_utc, - vr.link_used_date_utc, - vr.expire_at_utc, - vr.expire_date_utc, - vr.is_deleted, - vr.redirect_name, - vr.id_one_step_link, - vr.success_message, - vr.summary, - vr.rejection_reason, - vr.has_switched_to_mobile, - vr.is_verifier_rejected, - vr.config, - vr.metadata, - vr.created_at_utc, - vr.created_date_utc, - vr.updated_at_utc, - vr.updated_date_utc, - vr.dwh_extracted_at_utc, - p.currency, - p.payment_status, - p.payment_paid_date_utc, - p.total_amount_in_txn_currency, - p.amount_without_taxes_in_txn_currency, - p.total_amount_in_gbp, - p.amount_without_taxes_in_gbp, - ccp.checkin_cover_limit_amount_local_curr, - ( - ccp.checkin_cover_limit_amount_local_curr - * (p.total_amount_in_gbp / p.total_amount_in_txn_currency) - )::numeric(18, 4) as checkin_cover_limit_amount_in_gbp -from int_core__verification_requests vr -left join int_core__bookings b on vr.id_verification_request = b.id_verification_request -left join - stg_core__verification_set_to_verification_type vstvt - on vr.id_verification_set = vstvt.id_verification_set -left join - check_in_cover_payments p on vr.id_verification_request = p.id_verification_request -left join - int_core__check_in_cover_prices ccp on p.currency = ccp.local_currency_iso_4217 -left join int_core__unified_user gu on gu.id_user = vr.id_user_guest --- 15 is Check-in cover. --- Adding this condition results in only keeping guest journeys that offered the --- check-in cover -where vstvt.id_verification_type = 15 +select * +from pre_feature_flag_verification_requests From f1883aaa7a5a0718ae3a00917c54175375fa03a0 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 27 May 2025 15:03:48 +0200 Subject: [PATCH 2/5] second cte, then we union --- .../core/int_core__vr_check_in_cover.sql | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/models/intermediate/core/int_core__vr_check_in_cover.sql b/models/intermediate/core/int_core__vr_check_in_cover.sql index d4f4ef4..58c7f36 100644 --- a/models/intermediate/core/int_core__vr_check_in_cover.sql +++ b/models/intermediate/core/int_core__vr_check_in_cover.sql @@ -116,6 +116,104 @@ with -- Adding this condition results in only keeping guest journeys that offered the -- check-in cover where vstvt.id_verification_type = 15 + ), + post_feature_flag_verification_requests as ( + select + vr.id_verification_request, + vr.uuid_verification_request, + vr.id_verification_set, + vr.id_superhog_verified_set, + vr.id_payment_validation_set, + vr.id_user_guest, + vr.id_user_host, + b.id_booking, + b.id_accommodation, + vr.is_verification_request_complete, + ( + p.total_amount_in_txn_currency is not null + and not b.check_in_sits_in_future + ) as is_past_check_in, + ( + p.total_amount_in_txn_currency is not null + and b.check_in_sits_in_future + and vr.is_verification_request_complete + ) as is_awaiting_check_in, + p.total_amount_in_txn_currency is not null as cover_was_purchased, + ( + p.total_amount_in_txn_currency is null + and vr.is_verification_request_complete + ) as cover_was_rejected, + vr.verification_url, + vr.callback_url, + vr.redirect_url, + vr.logo, + gu.email as guest_email, + gu.last_name as last_name, + gu.first_name as first_name, + gu.phone_number as guest_phone_number, + vr.telephone_code, + vr.guest_phone_number_2, + b.check_in_at_utc, + b.check_in_date_utc, + b.check_out_at_utc, + b.check_out_date_utc, + vr.verification_estimated_started_at_utc as verification_start_at_utc, + vr.verification_estimated_started_date_utc as verification_start_date_utc, + vr.verification_estimated_completed_at_utc as verification_end_at_utc, + vr.verification_estimated_completed_date_utc as verification_end_date_utc, + vr.link_used_at_utc, + vr.link_used_date_utc, + vr.expire_at_utc, + vr.expire_date_utc, + vr.is_deleted, + vr.redirect_name, + vr.id_one_step_link, + vr.success_message, + vr.summary, + vr.rejection_reason, + vr.has_switched_to_mobile, + vr.is_verifier_rejected, + vr.config, + vr.metadata, + vr.created_at_utc, + vr.created_date_utc, + vr.updated_at_utc, + vr.updated_date_utc, + vr.dwh_extracted_at_utc, + p.currency, + p.payment_status, + p.payment_paid_date_utc, + p.total_amount_in_txn_currency, + p.amount_without_taxes_in_txn_currency, + p.total_amount_in_gbp, + p.amount_without_taxes_in_gbp, + ccp.checkin_cover_limit_amount_local_curr, + ( + ccp.checkin_cover_limit_amount_local_curr + * (p.total_amount_in_gbp / p.total_amount_in_txn_currency) + )::numeric(18, 4) as checkin_cover_limit_amount_in_gbp + from int_core__verification_requests vr + left join + int_core__bookings b + on vr.id_verification_request = b.id_verification_request + left join + stg_core__verification_set_to_verification_type vstvt + on vr.id_verification_set = vstvt.id_verification_set + left join + check_in_cover_payments p + on vr.id_verification_request = p.id_verification_request + left join + int_core__check_in_cover_prices ccp + on p.currency = ccp.local_currency_iso_4217 + left join int_core__unified_user gu on gu.id_user = vr.id_user_guest + -- 15 is Check-in cover. + -- Adding this condition results in only keeping guest journeys that offered the + -- check-in cover + where vstvt.id_verification_type = 99 ) + select * from pre_feature_flag_verification_requests +union all +select * +from post_feature_flag_verification_requests From 58c1ae5b8f4ebf74e5ff0ee3d82b35f417d17875 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 30 May 2025 15:46:45 +0200 Subject: [PATCH 3/5] put var in proper format --- dbt_project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_project.yml b/dbt_project.yml index 85f5b16..d5603c4 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -70,7 +70,7 @@ vars: # The timestamp of when the Guest Squad activated the Feature Flag that # activated the big bang refactor of the Guest Products logic. - "guest_products_feature_flag_activation_timestamp": "'2025-06-08T00:00:00Z'" + "guest_products_feature_flag_activation_timestamp": "'2025-06-08T00:00:00+00:00'" # A distant future date to use as a default when cutoff values are missing. "end_of_time": "'2050-12-31'" From 7339cf4c87e55d1a5af5d3ad79b00b96d0b2f111 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 30 May 2025 15:47:35 +0200 Subject: [PATCH 4/5] change logic in new CTE to use new tables --- .../core/int_core__vr_check_in_cover.sql | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/models/intermediate/core/int_core__vr_check_in_cover.sql b/models/intermediate/core/int_core__vr_check_in_cover.sql index 58c7f36..d83f34a 100644 --- a/models/intermediate/core/int_core__vr_check_in_cover.sql +++ b/models/intermediate/core/int_core__vr_check_in_cover.sql @@ -2,9 +2,16 @@ with int_core__verification_requests as ( select * from {{ ref("int_core__verification_requests") }} ), + stg_core__currency as (select * from {{ ref("stg_core__currency") }}), stg_core__verification_set_to_verification_type as ( select * from {{ ref("stg_core__verification_set_to_verification_type") }} ), + stg_core__verification_request_to_guest_product as ( + select * from {{ ref("stg_core__verification_request_to_guest_product") }} + ), + stg_core__guest_product_configuration_price_plan as ( + select * from {{ ref("stg_core__guest_product_configuration_price_plan") }} + ), int_core__bookings as (select * from {{ ref("int_core__bookings") }}), int_core__check_in_cover_prices as ( select * from {{ ref("int_core__check_in_cover_prices") }} @@ -121,9 +128,9 @@ with select vr.id_verification_request, vr.uuid_verification_request, - vr.id_verification_set, - vr.id_superhog_verified_set, - vr.id_payment_validation_set, + null as id_verification_set, + null as id_superhog_verified_set, + null as id_payment_validation_set, vr.id_user_guest, vr.id_user_host, b.id_booking, @@ -187,33 +194,45 @@ with p.amount_without_taxes_in_txn_currency, p.total_amount_in_gbp, p.amount_without_taxes_in_gbp, - ccp.checkin_cover_limit_amount_local_curr, + gpcpp.protection_limit_in_local_currency + as checkin_cover_limit_amount_local_curr, ( - ccp.checkin_cover_limit_amount_local_curr + gpcpp.protection_limit_in_local_currency * (p.total_amount_in_gbp / p.total_amount_in_txn_currency) )::numeric(18, 4) as checkin_cover_limit_amount_in_gbp from int_core__verification_requests vr + inner join + stg_core__verification_request_to_guest_product vrtogp + on vr.id_verification_request = vrtogp.id_verification_request + inner join + stg_core__guest_product_configuration_price_plan gpcpp + on vrtogp.id_guest_product_configuration_price_plan + = gpcpp.id_guest_product_configuration_price_plan + inner join stg_core__currency c on c.id_currency = gpcpp.id_currency left join int_core__bookings b on vr.id_verification_request = b.id_verification_request - left join - stg_core__verification_set_to_verification_type vstvt - on vr.id_verification_set = vstvt.id_verification_set left join check_in_cover_payments p on vr.id_verification_request = p.id_verification_request - left join - int_core__check_in_cover_prices ccp - on p.currency = ccp.local_currency_iso_4217 left join int_core__unified_user gu on gu.id_user = vr.id_user_guest - -- 15 is Check-in cover. - -- Adding this condition results in only keeping guest journeys that offered the - -- check-in cover - where vstvt.id_verification_type = 99 + where + p.currency = c.iso4217_code + and vrtogp.id_guest_product = 2 -- 2 is CIH + and vr.link_used_at_utc + >= {{ var("guest_products_feature_flag_activation_timestamp") }} -- This logic path only applies to VRs started after the FF was activated ) select * from pre_feature_flag_verification_requests -union all -select * -from post_feature_flag_verification_requests + +{%- if modules.datetime.datetime.now( + modules.pytz.timezone("UTC") + ) > modules.datetime.datetime.strptime( + var("guest_products_feature_flag_activation_timestamp"), + "'%Y-%m-%dT%H:%M:%S%z'", + ) -%} + union all + select * + from post_feature_flag_verification_requests +{% endif %} From c6a06b49e997b8094bc0aef9a111dcc0fd7a953f Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 30 May 2025 15:50:30 +0200 Subject: [PATCH 5/5] mention double logic in docs --- models/intermediate/core/schema.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 6195d9d..bc62a82 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -310,8 +310,14 @@ models: a first level of filtering. - name: int_core__vr_check_in_cover - description: "This tables holds information on verification requests - with Ckeck-in Hero available for the guests." + description: | + This tables holds information on verification requests with Ckeck-in Hero + available for the guests. + + The query has logic paths that cover both the Guest Products data model, + which started on June 2025, and the previous "CIH is a verification step" + model. + columns: - name: id_verification_request data_type: bigint