# Description Creates a first unified version of API verifications. This is a very simple model as it aims to capture the minimal essence of Verifications in a unified view. Any very-in-depth-API-specific detail is not available here. Additionally, I propagated the Check-in date in the Athena model. This is needed for API Bookings KPIs future models. # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [X] I have checked for DRY opportunities with other models and docs. - [X] I've picked the right materialization for the affected models. **Currently as a view, despite it's 70k records. If this grows we could consider other materialisations** # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #29374
43 lines
1.5 KiB
SQL
43 lines
1.5 KiB
SQL
{% set ok_status = "Approved" %}
|
|
with
|
|
int_athena__verifications as (select * from {{ ref("int_athena__verifications") }}),
|
|
stg_seed__athena_price_history as (
|
|
select * from {{ ref("stg_seed__athena_price_history") }}
|
|
),
|
|
-- CTE to rank verifications by updated_at_utc per id_booking
|
|
ranked_verifications as (
|
|
select
|
|
v.*,
|
|
row_number() over (
|
|
partition by v.id_booking order by v.updated_at_utc asc
|
|
) as rn
|
|
from int_athena__verifications v
|
|
where v.version = 'V1' and v.id_booking is not null
|
|
)
|
|
select
|
|
v.id_verification,
|
|
v.id_booking,
|
|
v.verification_status,
|
|
v.is_cancelled,
|
|
-- Charge for 1 night if number_nights = 0
|
|
case
|
|
when v.number_nights = 0 and v.verification_status = '{{ ok_status }}'
|
|
then ph.fee_per_night_gbp
|
|
when v.verification_status = '{{ ok_status }}'
|
|
then v.number_nights * ph.fee_per_night_gbp
|
|
else 0
|
|
end as ok_status_fee_in_gbp,
|
|
v.created_date_utc,
|
|
v.checkin_date_utc,
|
|
v.checkout_date_utc
|
|
from ranked_verifications v
|
|
left join
|
|
stg_seed__athena_price_history ph
|
|
-- The following condition ensures avoiding duplicates.
|
|
-- Keep in mind that the start_at_utc is inclusive to the price,
|
|
-- while the end_at_utc is exclusive.
|
|
on v.checkout_at_utc >= ph.start_at_utc
|
|
and v.checkout_at_utc < ph.end_at_utc
|
|
where
|
|
-- Select only the most recent verification for each id_booking
|
|
v.rn = 1
|