I modified the model of duplicated_bookings, I saw it had some errors and data that was not being used

This commit is contained in:
Joaquin Ossa 2024-07-31 12:44:54 +02:00
parent 7ec5d91c6a
commit 9996368e22
2 changed files with 34 additions and 11 deletions

View file

@ -1,9 +1,10 @@
{{ config(materialized="table", unique_key="id_booking") }}
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
-- This ugly thing below is true if the booking is duplicate and is not
-- the original, false otherwise
case
when
row_number() over (
partition by id_user_guest, id_accommodation, check_in_date_utc
@ -15,19 +16,41 @@ with
end as is_duplicate_booking,
*
from {{ ref("stg_core__booking") }}
),
-- This next queries are to obtain the original booking_id for those duplicated so
-- then we can associate to which booking_id they are duplicated from
duplicate_booking as (
select
id_user_guest,
id_accommodation,
check_in_date_utc,
count(*) as number_bookings
from {{ ref("stg_core__booking") }}
group by id_user_guest, id_accommodation, check_in_date_utc
),
stg_core__booking_duplicated as (
select bdf.*
from stg_core__booking_with_dup_flag bdf
left join
duplicate_booking db
on (
db.id_user_guest = bdf.id_user_guest
and db.id_accommodation = bdf.id_accommodation
and db.check_in_date_utc = bdf.check_in_date_utc
)
where bdf.is_duplicate_booking is false and db.number_bookings > 1
)
select
db.id_booking,
db.is_duplicate_booking,
b.id_booking as is_duplicating_booking_with_id
bd.id_booking as is_duplicating_booking_with_id
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
stg_core__booking_duplicated bd
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
bd.id_user_guest = db.id_user_guest
and bd.id_accommodation = db.id_accommodation
and bd.check_in_date_utc = db.check_in_date_utc
and bd.id_booking != db.id_booking
)
where b.is_duplicate_booking = false and db.is_duplicate_booking = true
where db.is_duplicate_booking is true

View file

@ -1377,7 +1377,7 @@ models:
accomodation and check-in date, the oldest one will have False as a value in this field,
and the other ones will have True as a value in this Failed."
Put simply, if you don't want to receive duplicates, filter this field to True.
Put simply, if you don't want to receive duplicates, filter this field to False.
- name: is_duplicating_booking_with_id
data_type: bigint