finished the ugly model

This commit is contained in:
Pablo Martin 2024-04-24 16:50:48 +02:00
parent 8e97b97377
commit c7120bd49c

View file

@ -1,7 +1,7 @@
/*
Welcome, fellow modeller.
This table exists because, surprisingly, telling whether a guest journey (AKA
This model exists because, surprisingly, telling whether a guest journey (AKA
Verification Request) is completed or not is rather complex.
This model is built mostly to encapsulate the chaos necessary to determine
@ -45,21 +45,62 @@ with
stg_core__verification_set_to_verification_type as (
select * from {{ ref("stg_core__verification_set_to_verification_type") }}
),
expected_verifications as (
select *
from stg_core__verification_set_to_verification_type vstvt
stg_core__verification_type as (
select * from {{ ref("stg_core__verification_type") }}
),
expected_verification_types as (
select
vr.id_verification_request,
vr.id_user_guest,
vt.verification_type,
null as id_verification_status
from stg_core__verification_request vr
left join
stg_core__verification_set_to_verification_type vstvt
on vstvt.id_verification_set = vr.id_verification_set
left join
stg_core__verification_type vt
on vstvt.id_verification_type = vt.id_verification_type
),
same_vr_verification_state as (
select vr.id_verification_request, v.verification, v.id_verification_status
from stg_core__verification v
left join
stg_core__verification_request vr
on vstvt.id_verification_set = vr.id_verification_set
on v.id_verification_request = vr.id_verification_request
where
v.verification in ('PaymentValidation', 'Contract')
and v.id_verification_request is not null
),
by_user_verification_state as (
select distinct vr.id_user_guest, v.verification, v.id_verification_status
from stg_core__verification v
left join
stg_core__verification_request vr
on v.id_verification_request = vr.id_verification_request
where verification not in ('PaymentValidation', 'Contract')
),
completeness_summary as (
select
evt.id_verification_request,
evt.verification_type,
coalesce(
t1.id_verification_status, t2.id_verification_status
) as global_id_verification_status
from expected_verification_types evt
left join
same_vr_verification_state as t1
on evt.id_verification_request = t1.id_verification_request
and evt.verification_type = t1.verification
left join
by_user_verification_state as t2
on evt.id_user_guest = t2.id_user_guest
and evt.verification_type = t2.verification
)
# ## THE WORK IN PROGRESS CODE FOR THIS IS IN DBEAVER SCRIPT 22
select
vr.id_verification_request,
case
when vr.id_user_guest is null
then 'Not Started'
when vr.id_verification_set is null
then 'Not Started'
else 'Complete'
end as verification_request_status
from stg_core__verification_request vr
id_verification_request,
count(1) as expected_verification_count,
sum(global_id_verification_status) as confirmed_verification_count,
count(1) = sum(global_id_verification_status) as is_verification_complete
from completeness_summary
group by id_verification_request