basic bookings and duplicates

This commit is contained in:
Pablo Martin 2024-03-20 17:23:08 +01:00
parent 09a62c701a
commit d8cf15be4a
2 changed files with 96 additions and 0 deletions

View file

@ -0,0 +1,40 @@
with
stg_core__booking as (select * from {{ ref("stg_core__booking") }}),
stg_core__booking_state as (select * from {{ ref("stg_core__booking_state") }}),
int_core__duplicate_bookings as (
select id_booking, is_duplicate_booking, is_duplicating_booking_with_id
from {{ ref("int_core__duplicate_bookings") }}
)
select
b.id_booking,
b.id_user_guest,
b.id_user_host,
b.id_integration,
b.id_accommodation,
b.id_booking_source,
b.id_verification_request,
b.id_staging_host_booking,
db.is_duplicate_booking,
db.is_duplicating_booking_with_id,
bs.booking_state,
b.check_in_at_utc,
b.check_in_date_utc,
b.check_out_at_utc,
b.check_out_date_utc,
b.summary,
b.guest_email,
b.guest_last_name,
b.guest_first_name,
b.guest_telephone,
b.additional_guests,
b.unsubscribe_verification_reminder,
b.created_at_utc,
b.created_date_utc,
b.updated_at_utc,
b.updated_date_utc,
b.dwh_extracted_at_utc
from stg_core__booking b
left join stg_core__booking_state bs on b.id_booking_state = bs.id_booking_state
left join int_core__duplicate_bookings as db on b.id_booking = db.id_booking
where b.updated_at_utc > '2024-01-01' and db.is_duplicate_booking is true

View file

@ -0,0 +1,56 @@
with
stg_core__booking_state as (select * from {{ ref("stg_core__booking_state") }}),
stg_core__booking_with_dup_flag as (
select
case -- This ugly thing below is true if the booking is duplicate, false if not
when
row_number() over (
partition by id_user_guest, id_accommodation, check_in_date_utc
order by id_booking asc
)
> 1
then true
else false
end as is_duplicate_booking,
*
from {{ ref("stg_core__booking") }}
)
select
db.id_booking,
db.id_user_guest,
db.id_user_host,
db.id_integration,
db.id_accommodation,
db.id_booking_source,
db.id_verification_request,
db.id_staging_host_booking,
db.is_duplicate_booking,
b.id_booking as is_duplicating_booking_with_id,
bs.booking_state,
db.check_in_at_utc,
db.check_in_date_utc,
db.check_out_at_utc,
db.check_out_date_utc,
db.summary,
db.guest_email,
db.guest_last_name,
db.guest_first_name,
db.guest_telephone,
db.additional_guests,
db.unsubscribe_verification_reminder,
db.created_at_utc,
db.created_date_utc,
db.updated_at_utc,
db.updated_date_utc,
db.dwh_extracted_at_utc
from stg_core__booking_with_dup_flag db
left join stg_core__booking_state bs on db.id_booking_state = bs.id_booking_state
left join
stg_core__booking_with_dup_flag b
on (
b.id_user_guest = db.id_user_guest
and b.id_accommodation = db.id_accommodation
and b.check_in_date_utc = db.check_in_date_utc
and b.id_booking != db.id_booking
)
where b.is_duplicate_booking = false and db.is_duplicate_booking = true