diff --git a/models/intermediate/core/int_core__guest_product_payments.sql b/models/intermediate/core/int_core__guest_product_payments.sql index 9fd6cae..9e14f83 100644 --- a/models/intermediate/core/int_core__guest_product_payments.sql +++ b/models/intermediate/core/int_core__guest_product_payments.sql @@ -4,24 +4,12 @@ {{ config(materialized="table") }} with stg_core__verification_to_payment as ( - 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 }} + select * from {{ ref("stg_core__verification_to_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") }} - where - created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - ), + stg_core__verification as (select * from {{ ref("stg_core__verification") }}), stg_core__verification_request as ( select * from {{ ref("stg_core__verification_request") }} ), @@ -66,7 +54,6 @@ 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 @@ -78,9 +65,23 @@ 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