From fba40788a67de2e80e5d10d4b34bca360489bb04 Mon Sep 17 00:00:00 2001 From: laurinehu Date: Tue, 7 May 2024 18:45:59 +0200 Subject: [PATCH] clean orga --- dbt/models/marts/daily/candidats_pk.sql | 10 ++++++ .../oneshot/ft_candidats_non_ft_sorties.sql | 32 ------------------- .../marts/oneshot/ft_candidats_sorties.sql | 24 -------------- .../oneshot/xpnord_sorties_candidats_asp.sql | 30 +++++++++++++++++ .../oneshot/xpnord_sorties_candidats_ft.sql | 18 +++++++++++ .../sql/xpnord_sorties_avec_nir.sql | 14 ++++---- 6 files changed, 66 insertions(+), 62 deletions(-) create mode 100644 dbt/models/marts/daily/candidats_pk.sql delete mode 100644 dbt/models/marts/oneshot/ft_candidats_non_ft_sorties.sql delete mode 100644 dbt/models/marts/oneshot/ft_candidats_sorties.sql create mode 100644 dbt/models/marts/oneshot/xpnord_sorties_candidats_asp.sql create mode 100644 dbt/models/marts/oneshot/xpnord_sorties_candidats_ft.sql rename dbt/models/marts/oneshot/ft_final.sql => scripts/sql/xpnord_sorties_avec_nir.sql (55%) diff --git a/dbt/models/marts/daily/candidats_pk.sql b/dbt/models/marts/daily/candidats_pk.sql new file mode 100644 index 00000000..0f668131 --- /dev/null +++ b/dbt/models/marts/daily/candidats_pk.sql @@ -0,0 +1,10 @@ +select + salarie_asp."hash_numéro_pass_iae" as "hash_numéro_pass_iae", + salarie_asp.salarie_id as id_salarie_asp, + candidat_emploi.id as id_candidat_emplois, + candidat_emploi.hash_nir as hash_nir +from {{ source('fluxIAE', 'fluxIAE_Salarie') }} as salarie_asp +left join {{ source('emplois', 'pass_agréments') }} as pass + on salarie_asp."hash_numéro_pass_iae" = pass."hash_numéro_pass_iae" +left join {{ ref('candidats') }} as candidat_emploi + on candidat_emploi.id = pass.id_candidat diff --git a/dbt/models/marts/oneshot/ft_candidats_non_ft_sorties.sql b/dbt/models/marts/oneshot/ft_candidats_non_ft_sorties.sql deleted file mode 100644 index fb66aed4..00000000 --- a/dbt/models/marts/oneshot/ft_candidats_non_ft_sorties.sql +++ /dev/null @@ -1,32 +0,0 @@ -select - c.hash_nir, - ft_candidates.nir_hash, - c.id as id_salarie_emplois, - salarie.salarie_id as id_salarie_asp, - sorties.date_sortie, - sorties.type_structure, - msct.motif_de_sortie -from {{ ref('fluxIAE_Salarie_v2') }} as salarie --- pour récupérer le nir pour ensuite pouvoir filtrer les candidats non ft -left join {{ source('emplois', 'pass_agréments') }} as pass - on salarie."hash_numéro_pass_iae" = pass."hash_numéro_pass_iae" -left join {{ ref('candidats') }} as c - on c.id = pass.id_candidat --- pour filtrer les candidats non ft -left join {{ ref('ft_candidats_nord') }} as ft_candidates - on ft_candidates.nir_hash = c.hash_nir --- pour récupérer la sortie -left join {{ ref('sorties_definitives') }} as sorties - on sorties.contrat_id_pph = salarie.salarie_id --- pour récupérer le motif de sortie -left join {{ ref('motif_sortie_contrat_termine') }} as msct - on sorties.contrat_id_pph = msct.pph_id and sorties.date_sortie = msct.date_fin_reelle --- on ne garde que les candidats : --- - du nord --- - un pass IAE a été attribué entre le 1 janvier 2021 et le 30 juin 2023. -where - salarie.salarie_code_dpt = '059' - and pass."date_début" > '2021-01-01' - and pass."date_début" < '2023-06-30' - and pass.date_sortie is not null --- and ft.hash_nir is null diff --git a/dbt/models/marts/oneshot/ft_candidats_sorties.sql b/dbt/models/marts/oneshot/ft_candidats_sorties.sql deleted file mode 100644 index 6b48e775..00000000 --- a/dbt/models/marts/oneshot/ft_candidats_sorties.sql +++ /dev/null @@ -1,24 +0,0 @@ -select - ft.nir_hash, - c.id as id_salarie_emplois, - salarie.salarie_id as id_salarie_asp, - pass."hash_numéro_pass_iae", - sorties.contrat_id_pph, - sorties.date_sortie, - sorties.type_structure, - msct.motif_de_sortie -from {{ source('oneshot', 'ft_iae_nord') }} as ft -left join {{ ref('candidats') }} as c - on c.hash_nir = ft.nir_hash --- duplication des candidats car un candidat peut avoir plusieurs pass -left join {{ source('emplois', 'pass_agréments') }} as pass - on pass.id_candidat = c.id -left join {{ ref('fluxIAE_Salarie_v2') }} as salarie - on salarie."hash_numéro_pass_iae" = pass."hash_numéro_pass_iae" --- ici on croise avec les sorties définitives --- duplication des candidats parceque certains candidats ont plusieurs sorties -left join {{ ref('sorties_definitives') }} as sorties - on sorties.contrat_id_pph = salarie.salarie_id --- pour récupérer le motif de sortie -left join {{ ref('motif_sortie_contrat_termine') }} as msct - on sorties.contrat_id_pph = msct.pph_id and sorties.date_sortie = msct.date_fin_reelle diff --git a/dbt/models/marts/oneshot/xpnord_sorties_candidats_asp.sql b/dbt/models/marts/oneshot/xpnord_sorties_candidats_asp.sql new file mode 100644 index 00000000..6a836986 --- /dev/null +++ b/dbt/models/marts/oneshot/xpnord_sorties_candidats_asp.sql @@ -0,0 +1,30 @@ +select + candidats.hash_nir as nir_emplois, + ft_candidats.nir_hash as nir_ft, + candidats.id_candidat_emplois as id_candidat_emplois, + candidats.id_salarie_asp as id_salarie_asp, + sorties.date_sortie, + sorties.type_structure, + msct.motif_de_sortie +from {{ ref('candidats_pk') }} as candidats +left join {{ ref('fluxIAE_Salarie_v2') }} as salarie_asp + on salarie_asp.salarie_id = candidats.id_salarie_asp +left join {{ source('emplois', 'pass_agréments') }} as pass + on pass."hash_numéro_pass_iae" = candidats."hash_numéro_pass_iae" +-- pour filtrer les candidats non ft +left join {{ ref('ft_candidats_nord') }} as ft_candidats + on ft_candidats.nir_hash = candidats.hash_nir +-- pour récupérer la sortie +left join {{ ref('sorties_definitives') }} as sorties + on sorties.contrat_id_pph = candidats.id_salarie_asp +-- pour récupérer le motif de sortie +left join {{ ref('motif_sortie_contrat_termine') }} as msct + on sorties.contrat_id_pph = msct.pph_id and sorties.date_sortie = msct.date_fin_reelle +-- on ne garde que les candidats : +-- - du nord +-- - un pass IAE a été attribué entre le 1 janvier 2021 et le 30 juin 2023. +where + salarie_asp.salarie_code_dpt = '059' + and pass."date_début" > '2021-01-01' + and pass."date_début" < '2023-06-30' + and sorties.date_sortie is not null diff --git a/dbt/models/marts/oneshot/xpnord_sorties_candidats_ft.sql b/dbt/models/marts/oneshot/xpnord_sorties_candidats_ft.sql new file mode 100644 index 00000000..e84939c1 --- /dev/null +++ b/dbt/models/marts/oneshot/xpnord_sorties_candidats_ft.sql @@ -0,0 +1,18 @@ +select + candidats.hash_nir as nir_emplois, + ft_candidats.nir_hash as nir_ft, + candidats.id_candidat_emplois as id_candidat_emplois, + candidats.id_salarie_asp as id_salarie_asp, + sorties.date_sortie, + sorties.type_structure, + msct.motif_de_sortie +from {{ source('oneshot', 'ft_iae_nord') }} as ft_candidats +left join {{ ref('candidats_pk') }} as candidats + on candidats.hash_nir = ft_candidats.nir_hash +-- ici on croise avec les sorties définitives +-- duplication des candidats parceque certains candidats ont plusieurs sorties +left join {{ ref('sorties_definitives') }} as sorties + on sorties.contrat_id_pph = candidats.id_salarie_asp +-- pour récupérer le motif de sortie +left join {{ ref('motif_sortie_contrat_termine') }} as msct + on sorties.contrat_id_pph = msct.pph_id and sorties.date_sortie = msct.date_fin_reelle diff --git a/dbt/models/marts/oneshot/ft_final.sql b/scripts/sql/xpnord_sorties_avec_nir.sql similarity index 55% rename from dbt/models/marts/oneshot/ft_final.sql rename to scripts/sql/xpnord_sorties_avec_nir.sql index c9bacc7c..66489906 100644 --- a/dbt/models/marts/oneshot/ft_final.sql +++ b/scripts/sql/xpnord_sorties_avec_nir.sql @@ -4,10 +4,11 @@ select ft.date_sortie, ft.type_structure, ft.motif_de_sortie, - -- ajouter ici la colonne nir récupérée de la jointure + nir_corresp.nir, case when nir_hash is not null then 'oui' else 'non' end as ft -from {{ ref("ft_candidats_sorties") }} as ft --- ajouter ici un left join sur la table de correspondance nir/id_salarie +from {{ ref("xpnord_sorties_candidats_ft") }} as ft +left join {{ ref("nir_corresp") }} as nir_corresp + on nir_corresp.hash_nir = ft.nir_ft where ft.date_sortie is not null union select @@ -16,8 +17,9 @@ select ft.date_sortie, ft.type_structure, ft.motif_de_sortie, - -- ajouter ici la colonne nir récupérée de la jointure + nir_corresp.nir case when nir_hash is not null then 'oui' else 'non' end as ft -from {{ ref("ft_candidats_non_ft_sorties") }} as ft --- ajouter ici un left join sur la table de correspondance nir/id_salarie +from {{ ref("xpnord_sorties_candidats_asp") }} as ft +left join {{ ref("nir_corresp") }} as nir_corresp + on nir_corresp.hash_nir = ft.nir_emplois where ft.date_sortie is not null