-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipeline) : Ensure the zone_diffusion_codes for DROM/COM
There were cases where we did have the zone_diffusion_code set to "97" which can't be right, as it would mean that a given service coyuld be available across the oceans. Let's fix it and set the correct, 3-digit department number. This will also enable their search as we now (since the "new" communes) search for a match agains commune.departement, which can be 3 digits. There is also now a complete data validation that leaves the errors as a specific table in the public_dbt_test__audit schema.
- Loading branch information
Showing
4 changed files
with
145 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
pipeline/dbt/models/staging/decoupage_administratif/stg_decoupage_administratif__epcis.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
{{ stg_source_header('decoupage_administratif', 'epcis') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
code AS "code", | ||
nom AS "nom" | ||
FROM source | ||
ORDER BY code | ||
) | ||
|
||
SELECT * FROM final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* Executed automatically when the dependent models are rebuilt. | ||
This test checks that the zone_diffusion_code field in the services table | ||
is consistent with the reference tables for communes, departements, epcis and regions. | ||
If the code is not found in the reference tables, the row is returned in the result set. | ||
Examples: | ||
-[ RECORD 6 ]-------+----------------------------------- | ||
_di_surrogate_id | soliguide-6181a6e18ac6b179ffb9ffe8 | ||
zone_diffusion_type | commune | ||
zone_diffusion_code | | ||
-[ RECORD 7 ]-------+----------------------------------- | ||
_di_surrogate_id | odspep-49760_commune_60038 | ||
zone_diffusion_type | commune | ||
zone_diffusion_code | 60038 | ||
-[ RECORD 11895 ]---+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
_di_surrogate_id | dora-ed2692ba-e95d-484b-99e2-f994f9636f7f | ||
zone_diffusion_type | epci | ||
zone_diffusion_code | 200035459 | ||
-[ RECORD 11896 ]---+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
_di_surrogate_id | dora-edfa0021-a58d-435e-9138-00a595558254 | ||
zone_diffusion_type | region | ||
zone_diffusion_code | 59 | ||
*/ | ||
|
||
{{ config(severity = 'warn', store_failures = true) }} | ||
|
||
with invalid_communes as ( | ||
select | ||
services._di_surrogate_id, | ||
services.zone_diffusion_type, | ||
services.zone_diffusion_code | ||
from | ||
{{ ref('int__union_services__enhanced') }} as services | ||
left join {{ ref('stg_decoupage_administratif__communes') }} as communes | ||
on services.zone_diffusion_code = communes.code | ||
where services.zone_diffusion_type='commune' and communes.code is null | ||
order by services._di_surrogate_id | ||
), | ||
|
||
invalid_departements as ( | ||
select | ||
services._di_surrogate_id, | ||
services.zone_diffusion_type, | ||
services.zone_diffusion_code | ||
from | ||
{{ ref('int__union_services__enhanced') }} as services | ||
left join {{ ref('stg_decoupage_administratif__departements') }} as departements | ||
on services.zone_diffusion_code = departements.code | ||
where services.zone_diffusion_type='departement' and departements.code is null | ||
order by services._di_surrogate_id | ||
), | ||
|
||
invalid_epcis as ( | ||
select | ||
services._di_surrogate_id, | ||
services.zone_diffusion_type, | ||
services.zone_diffusion_code | ||
from | ||
{{ ref('int__union_services__enhanced') }} as services | ||
left join {{ ref('stg_decoupage_administratif__epcis') }} as epcis | ||
on services.zone_diffusion_code = epcis.code | ||
where services.zone_diffusion_type='epci' and epcis.code is null | ||
order by services._di_surrogate_id | ||
), | ||
|
||
invalid_regions as ( | ||
select | ||
services._di_surrogate_id, | ||
services.zone_diffusion_type, | ||
services.zone_diffusion_code | ||
from | ||
{{ ref('int__union_services__enhanced') }} as services | ||
left join {{ ref('stg_decoupage_administratif__regions') }} as regions | ||
on services.zone_diffusion_code = regions.code | ||
where services.zone_diffusion_type='region' and regions.code is null | ||
order by services._di_surrogate_id | ||
), | ||
|
||
validation_errors as ( | ||
select * from invalid_communes | ||
union all | ||
select * from invalid_departements | ||
union all | ||
select * from invalid_epcis | ||
union all | ||
select * from invalid_regions | ||
) | ||
|
||
select * | ||
from validation_errors | ||
|