finished the ugly model
This commit is contained in:
parent
8e97b97377
commit
c7120bd49c
1 changed files with 56 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Welcome, fellow modeller.
|
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.
|
Verification Request) is completed or not is rather complex.
|
||||||
|
|
||||||
This model is built mostly to encapsulate the chaos necessary to determine
|
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 (
|
stg_core__verification_set_to_verification_type as (
|
||||||
select * from {{ ref("stg_core__verification_set_to_verification_type") }}
|
select * from {{ ref("stg_core__verification_set_to_verification_type") }}
|
||||||
),
|
),
|
||||||
expected_verifications as (
|
stg_core__verification_type as (
|
||||||
select *
|
select * from {{ ref("stg_core__verification_type") }}
|
||||||
from stg_core__verification_set_to_verification_type vstvt
|
),
|
||||||
|
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
|
left join
|
||||||
stg_core__verification_request vr
|
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
|
select
|
||||||
vr.id_verification_request,
|
id_verification_request,
|
||||||
case
|
count(1) as expected_verification_count,
|
||||||
when vr.id_user_guest is null
|
sum(global_id_verification_status) as confirmed_verification_count,
|
||||||
then 'Not Started'
|
count(1) = sum(global_id_verification_status) as is_verification_complete
|
||||||
when vr.id_verification_set is null
|
from completeness_summary
|
||||||
then 'Not Started'
|
group by id_verification_request
|
||||||
else 'Complete'
|
|
||||||
end as verification_request_status
|
|
||||||
from stg_core__verification_request vr
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue