From 30c73b1ab9891138e7ed940bf455a131966c3fd3 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 4 Oct 2024 16:29:57 +0200 Subject: [PATCH] duplicate athena verifications --- .../athena/int_athena__verifications.sql | 49 +++++++++++++++++++ ...> int_athena__verifications_with_fees.sql} | 6 +-- .../edeposit__guesty_verifications.sql | 20 ++++---- 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 models/intermediate/athena/int_athena__verifications.sql rename models/intermediate/athena/{int_athena__guesty_verifications.sql => int_athena__verifications_with_fees.sql} (87%) diff --git a/models/intermediate/athena/int_athena__verifications.sql b/models/intermediate/athena/int_athena__verifications.sql new file mode 100644 index 0000000..5bc57b9 --- /dev/null +++ b/models/intermediate/athena/int_athena__verifications.sql @@ -0,0 +1,49 @@ +with + stg_edeposit__verifications as ( + select * from {{ ref("stg_edeposit__verifications") }} + ) +select + -- note that these ids are not the same as the ones found in Core DWH + -- they are completely unrelated + id_verification, + id_booking, + id_user_partner, + id_accommodation, + version, + case when version = 'V1' then 'Guesty' else null end as verification_source, + verification_status, + nightly_fee_local, + cast(checkout_at_utc as date) - cast(checkin_at_utc as date) as number_nights, + email_flag, + phone_flag, + watch_list, + channel, + checkin_at_utc, + cast(checkin_at_utc as date) as checkin_date_utc, + checkout_at_utc, + cast(checkout_at_utc as date) as checkout_date_utc, + is_cancelled, + cancelled_at_utc, + cast(cancelled_at_utc as date) as cancelled_date_utc, + user_email, + guest_email, + guest_last_name, + guest_first_name, + guest_telephone, + company_name, + property_manager_name, + property_manager_email, + listing_name, + listing_town, + listing_country, + listing_postcode, + pets_allowed, + status_updated_at_utc, + status_updated_date_utc, + updated_at_utc, + athena_creation_at_utc, + athena_creation_date_utc, + created_at_utc, + created_date_utc +from stg_edeposit__verifications +where version = 'V1' diff --git a/models/intermediate/athena/int_athena__guesty_verifications.sql b/models/intermediate/athena/int_athena__verifications_with_fees.sql similarity index 87% rename from models/intermediate/athena/int_athena__guesty_verifications.sql rename to models/intermediate/athena/int_athena__verifications_with_fees.sql index 7aa8594..0f63f91 100644 --- a/models/intermediate/athena/int_athena__guesty_verifications.sql +++ b/models/intermediate/athena/int_athena__verifications_with_fees.sql @@ -2,9 +2,7 @@ -- 2GBP/booked night if booking is approved, to be charged on checkout {% set cost_per_night = 2 %} with - int_edeposit__verifications as ( - select * from {{ ref("int_edeposit__verifications") }} - ), + int_athena__verifications as (select * from {{ ref("int_athena__verifications") }}), -- CTE to rank verifications by updated_at_utc per id_booking ranked_verifications as ( select @@ -12,7 +10,7 @@ with row_number() over ( partition by v.id_booking order by v.updated_at_utc asc ) as rn - from int_edeposit__verifications v + from int_athena__verifications v where v.version = 'V1' and v.id_booking is not null ) select diff --git a/models/reporting/edeposit/edeposit__guesty_verifications.sql b/models/reporting/edeposit/edeposit__guesty_verifications.sql index b0c018d..1c9e9e1 100644 --- a/models/reporting/edeposit/edeposit__guesty_verifications.sql +++ b/models/reporting/edeposit/edeposit__guesty_verifications.sql @@ -1,14 +1,14 @@ with - int_edeposit__guesty_verifications as ( - select * from {{ ref("int_athena__guesty_verifications") }} + int_athena__verifications_with_fees as ( + select * from {{ ref("int_athena__verifications_with_fees") }} ) select - gv.id_verification as id_verification, - gv.id_booking as id_booking, - gv.verification_status as verification_status, - gv.is_cancelled as is_cancelled, - gv.ok_status_fee_in_gbp as ok_status_fee_in_gbp, - gv.created_date_utc as created_date_utc, - gv.checkout_date_utc as checkout_date_utc -from int_edeposit__guesty_verifications gv + avf.id_verification as id_verification, + avf.id_booking as id_booking, + avf.verification_status as verification_status, + avf.is_cancelled as is_cancelled, + avf.ok_status_fee_in_gbp as ok_status_fee_in_gbp, + avf.created_date_utc as created_date_utc, + avf.checkout_date_utc as checkout_date_utc +from int_athena__verifications_with_fees avf