From 92c8331ae4810639c32a7130d3fe21c998d6c9c3 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 19 May 2025 15:44:06 +0200 Subject: [PATCH] refactor --- .../core/int_core__guest_product_payments.sql | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/models/intermediate/core/int_core__guest_product_payments.sql b/models/intermediate/core/int_core__guest_product_payments.sql index 9e14f83..9fd6cae 100644 --- a/models/intermediate/core/int_core__guest_product_payments.sql +++ b/models/intermediate/core/int_core__guest_product_payments.sql @@ -4,12 +4,24 @@ {{ config(materialized="table") }} with stg_core__verification_to_payment as ( - select * from {{ ref("stg_core__verification_to_payment") }} + select * + from {{ ref("stg_core__verification_to_payment") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and id_verification_payment_type + = {{ check_in_cover_as_id_verification_payment }} ), stg_core__verification_payment_type as ( select * from {{ ref("stg_core__verification_payment_type") }} ), - stg_core__verification as (select * from {{ ref("stg_core__verification") }}), + stg_core__verification as ( + select * + from {{ ref("stg_core__verification") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + ), stg_core__verification_request as ( select * from {{ ref("stg_core__verification_request") }} ), @@ -54,6 +66,7 @@ with upper(coalesce(ps.payment_status, 'UNKNOWN')) as payment_status, p.notes from stg_core__verification_to_payment vtp + left join stg_core__verification v on vtp.id_verification = v.id_verification inner join stg_core__verification_payment_type vpt on vtp.id_verification_payment_type = vpt.id_verification_payment_type @@ -65,23 +78,9 @@ with on vtp.payment_due_date_utc = r.rate_date_utc and p.currency = r.from_currency and r.to_currency = 'GBP' - left join stg_core__verification v on vtp.id_verification = v.id_verification left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request - where - vtp.id_verification_payment_type - = {{ check_in_cover_as_id_verification_payment }} - -- Following is to enhance the performance of the query once Guest Product - -- payment data follows exclusively the dedicated Guest Product models - and v.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and vtp.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and p.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and vr.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) ), guest_product_payments_from_guest_product_flow as ( select