Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipeline): add odspep mapping for services #27 #31

Merged
merged 21 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
aa02916
feature(pipeline): add odspep mapping for services #27
ColinMaudry Feb 20, 2023
4104511
feature(pipeline): add zone_diffusion to odspep mapping (only dep and…
ColinMaudry Feb 21, 2023
90087d9
feature(pipeline): add zone_diffusion to odspep mapping (only com and…
ColinMaudry Feb 21, 2023
052bc14
feature(pipeline): add zone_diffusion to odspep mapping (only com and…
ColinMaudry Feb 21, 2023
5be6384
feature(pipeline): add zone_diffusion to odspep mapping (dir ofii) #27
ColinMaudry Feb 21, 2023
7a104fe
Merge branch 'main' into odspep
ColinMaudry Feb 21, 2023
60c9fdc
chore(lint): order select statements in ascending complexity
ColinMaudry Feb 21, 2023
2b4f360
doc(dbt): add table documentation in _odspep__models.yml
ColinMaudry Feb 22, 2023
f4b177a
docs(dbt): rephrase table description
ColinMaudry Feb 22, 2023
d51cb6e
chore(odspep): use double quotes when renaming columns (vs. transform…
ColinMaudry Feb 22, 2023
c395f7c
feat(odspep): add surrogate key to *_ressource data
ColinMaudry Feb 22, 2023
9e9ed55
feat(odspep): test id uniqueness in int services and int aggregated_r…
ColinMaudry Feb 22, 2023
8a601ed
chore(odspep): merge changes from the review
ColinMaudry Feb 22, 2023
5cd9ea6
feat(odspep): enable unique service id using unique zone code #30
ColinMaudry Feb 22, 2023
afb8878
fix(odspep): unique ressource and service id (dbt tested) #30
ColinMaudry Feb 22, 2023
d61cd1c
feat(odspep): disabled dedup structures, removed aggr ressource id #30
ColinMaudry Feb 23, 2023
07c5457
chore(odspep): renamed aggregated_ressource => zones_diffusion #30
ColinMaudry Feb 23, 2023
14ea82e
fix(odspep): readded odspep structures to int__structures (not dedupl…
ColinMaudry Feb 23, 2023
a2232ed
Merge branch 'main' into odspep
ColinMaudry Feb 23, 2023
8476765
chore(odspep): cleanup
vmttn Feb 24, 2023
5903f2b
feat(odspep): basic dedup of structures id_res
vmttn Feb 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pipeline/dbt/models/intermediate/int__services.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ WITH services AS (
dbt_utils.union_relations(
relations=[
ref('int_dora__services'),
ref('int_mediation_numerique__services')
ref('int_mediation_numerique__services'),
ref('int_odspep__services'),
],
column_override={
"types": "TEXT[]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version: 2

models:
- name: int_odspep__aggregated_ressource
vmttn marked this conversation as resolved.
Show resolved Hide resolved
- name: int_odspep__enhanced_res_partenariales
- name: int_odspep__structures
- name: int_odspep__structures
- name: int_odspep__services
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- This model aggregates all the *_RESSOURCE ODSPEP tables in the same table, aligned on a common set of columns
ColinMaudry marked this conversation as resolved.
Show resolved Hide resolved

WITH regions AS (
SELECT
id,
id_res,
code_region_reg AS code,
'Région' AS type_code
FROM {{ ref('stg_odspep__regions') }}
),

departements AS (
SELECT
id,
id_res,
code_departement_dpt AS code,
'Département' AS type_code
FROM {{ ref('stg_odspep__departements') }}
),

communes AS (
SELECT
id,
id_res,
code_commune_com AS code,
'Commune' AS type_code
FROM {{ ref('stg_odspep__communes') }}
),

bassins AS (
SELECT
id,
id_res,
code_bassin_bas AS code,
'Bassin' AS type_code
FROM {{ ref('stg_odspep__bassins') }}
),

dir_territoriale_ofii AS (
SELECT
id,
vmttn marked this conversation as resolved.
Show resolved Hide resolved
id_res,
code_dit AS code,
'DT OFII' AS type_code
FROM {{ ref('stg_odspep__dir_territoriale_ofii') }}
),

final AS (
vmttn marked this conversation as resolved.
Show resolved Hide resolved

SELECT * FROM regions
UNION
SELECT * FROM departements
UNION
SELECT * FROM communes
UNION
SELECT * FROM bassins
UNION
SELECT * FROM dir_territoriale_ofii
)

SELECT * FROM final
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ contacts AS (
SELECT * FROM {{ ref('stg_odspep__contacts') }}
),

aggregated_ressource AS (
SELECT * FROM {{ ref('int_odspep__aggregated_ressource') }}
),


final AS (
SELECT
{{ dbt_utils.star(
Expand All @@ -26,10 +31,17 @@ final AS (
relation_alias='contacts',
from=ref('stg_odspep__contacts'),
except=['id', 'id_ctc', 'id_res'])
}},
{{ dbt_utils.star(
relation_alias='aggregated_ressource',
from=ref('int_odspep__aggregated_ressource'),
except=['id', 'id_res'],
)
}}
FROM ressources_partenariales
LEFT JOIN adresses ON ressources_partenariales.id_adr = adresses.id
LEFT JOIN contacts ON ressources_partenariales.id_ctc = contacts.id
LEFT JOIN aggregated_ressource ON ressources_partenariales.id_res = aggregated_ressource.id_res
vmttn marked this conversation as resolved.
Show resolved Hide resolved
)

SELECT * FROM final
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
WITH ressources_partenariales AS (
SELECT * FROM {{ ref('int_odspep__enhanced_res_partenariales') }}
),

final AS (
SELECT
id_res AS "id",
"service" AS "nom",
'odspep' AS "source",
service_description AS "presentation_resume",
date_fin_valid AS "date_suspension",
date_derniere_modif AS "date_modification",
code AS zone_diffusion_code,
type_code AS zone_diffusion_type,
ColinMaudry marked this conversation as resolved.
Show resolved Hide resolved
CASE WHEN prescriptible
THEN ARRAY['demandeur-demploi']::TEXT[]
END AS "profils",
-- Mapping: https://www.notion.so/dora-beta/Explorer-ODSPEP-du-23-01-22-48e1d505c7cb4fdb9e3ec789449e7ca7#24743be5aac94306b6261e8e6c2f748c
CASE type_res_part
WHEN '3' THEN ARRAY['creation-dactivite']::TEXT[]
WHEN '5' THEN ARRAY['handicap']::TEXT[]
WHEN '6' THEN ARRAY['accompagnement-social-et-professionnel-personnalise']::TEXT[]
WHEN '8' THEN ARRAY['mobilite']::TEXT[]
WHEN '9' THEN ARRAY['numerique']::TEXT[]
END AS "thematiques"

FROM ressources_partenariales
ORDER BY 1

vmttn marked this conversation as resolved.
Show resolved Hide resolved
)

SELECT * FROM final
32 changes: 30 additions & 2 deletions pipeline/dbt/models/sources/odspep/_odspep__models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,42 @@ models:
tests:
- not_null
- unique

- name: stg_odspep__horaires
columns:
- name: id_hor
tests:
- not_null
- unique

- name: stg_odspep__regions
columns:
- name: id_res
vmttn marked this conversation as resolved.
Show resolved Hide resolved
comment: id_res are not unique in this table
tests:
- not_null
- name: stg_odspep__departements
columns:
- name: id_res
comment: id_res are not unique in this table
tests:
- not_null
- name: stg_odspep__communes
columns:
- name: id_res
comment: id_res are not unique in this table
ColinMaudry marked this conversation as resolved.
Show resolved Hide resolved
tests:
- not_null
- name: stg_odspep__bassins
columns:
- name: id_res
comment: id_res are not unique in this table
tests:
- not_null
- name: stg_odspep__dir_territoriale_ofii
columns:
- name: id_res
comment: id_res are not unique in this table
tests:
- not_null
- name: stg_odspep__res_partenariales
columns:
- name: id_res
Expand Down
17 changes: 17 additions & 0 deletions pipeline/dbt/models/sources/odspep/stg_odspep__bassins.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH source AS (
SELECT *
FROM {{ source('odspep', 'DD009_BASSIN_RESSOURCE') }}
),


final AS (
SELECT
"ID_BAS" AS "id",
"ID_BAS" AS "id_bas",
"ID_RES" AS "id_res",
"CODE_BASSIN_BAS" AS "code_bassin_bas"

FROM source
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions pipeline/dbt/models/sources/odspep/stg_odspep__communes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH source AS (
SELECT *
FROM {{ source('odspep', 'DD009_COMMUNE_RESSOURCE') }}
),


final AS (
SELECT
"ID_COM" AS "id",
"ID_COM" AS "id_com",
"ID_RES" AS "id_res",
"CODE_COMMUNE_COM" AS "code_commune_com"

FROM source
)

SELECT * FROM final
17 changes: 17 additions & 0 deletions pipeline/dbt/models/sources/odspep/stg_odspep__departements.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH source AS (
SELECT *
FROM {{ source('odspep', 'DD009_DEPARTEMENT_RESSOURCE') }}
),


final AS (
SELECT
"ID_DPT" AS "id",
"ID_DPT" AS "id_dpt",
"ID_RES" AS "id_res",
"CODE_DEPARTEMENT_DPT" AS "code_departement_dpt"

FROM source
)

SELECT * FROM final
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH source AS (
SELECT *
FROM {{ source('odspep', 'DD009_DIR_TERRITORIALE_OFII') }}
),


final AS (
SELECT
"ID_DIT" AS "id",
"ID_DIT" AS "id_dit",
"ID_RES" AS "id_res",
"CODE_DIT" AS "code_dit"

FROM source
)

SELECT * FROM final
22 changes: 22 additions & 0 deletions pipeline/dbt/models/sources/odspep/stg_odspep__regions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
WITH source AS (
SELECT *
FROM {{ source('odspep', 'DD009_REGION_RESSOURCE_1') }}
UNION
SELECT *
FROM {{ source('odspep', 'DD009_REGION_RESSOURCE_2') }}

),


final AS (
SELECT
"ID_REG" AS "id",
"ID_REG" AS "id_reg",
"ID_RES" AS "id_res",
"CODE_REGION_REG" AS "code_region_reg",
'Région' AS zone_diffusion_type

FROM source
)

SELECT * FROM final
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final AS (
"RESPONSABLE_RSP" AS "responsable",
"COMMENTAIRES_HORAIRE_RSP" AS "commentaires_horaire",
"NUMERO_RSP" AS "numero",
"PRESCRIPTIBLE_RSP" AS "prescriptible",
"PRESCRIPTIBLE_RSP"::BOOLEAN AS "prescriptible",
"TYPE_RES_PART_RSP" AS "type_res_part",
"PROPRIETAIRE_RSP" AS "proprietaire",
"CREATEUR_RSP" AS "createur",
Expand Down