Skip to content

Commit

Permalink
dbt transformation for cd39
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinMaudry committed Jun 21, 2023
1 parent d82d933 commit c495a91
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pipeline/dbt/models/intermediate/cd39/_cd39__models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 2

models:
- name: int_cd39__structures
- name: int_cd39__services
35 changes: 35 additions & 0 deletions pipeline/dbt/models/intermediate/cd39/int_cd39__services.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
WITH structures_services AS (
SELECT * FROM {{ ref('stg_cd39__structures_services') }}
),

final AS (
SELECT
id_service AS "id",
structure_id AS "structure_id",
NULL AS "siret",
NULL::BOOLEAN AS "antenne",
NULL AS "rna",
nom_service AS "nom",
commune AS "commune",
code_postal AS "code_postal",
NULL AS "code_insee",
adresse AS "adresse",
NULL AS "complement_adresse",
NULL AS "longitude",
NULL AS "latitude",
telephone AS "telephone",
courriel_service AS "courriel",
site_web AS "site_web",
_di_source_id AS "source",
NULL AS "lien_source",
NULL AS "horaires_ouverture",
NULL AS "accessibilite",
NULL::TEXT [] AS "labels_nationaux",
NULL::TEXT [] AS "labels_autres",
thematiques::TEXT [] AS "thematiques",
"presentation_detail" AS "presentation_detail",
NULL AS "date_maj"
FROM structures_services
)

SELECT * FROM final
36 changes: 36 additions & 0 deletions pipeline/dbt/models/intermediate/cd39/int_cd39__structures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
WITH structures_services AS (
SELECT * FROM {{ ref('stg_cd39__structures_services') }}
),

final AS (
SELECT
structure_id AS "id",
NULL AS "siret",
NULL::BOOLEAN AS "antenne",
NULL AS "rna",
nom_structure AS "nom",
commune AS "commune",
code_postal AS "code_postal",
NULL AS "code_insee",
adresse AS "adresse",
NULL AS "complement_adresse",
NULL AS "longitude",
NULL AS "latitude",
telephone AS "telephone",
courriel_structure AS "courriel",
site_web AS "site_web",
_di_source_id AS "source",
NULL AS "lien_source",
NULL AS "horaires_ouverture",
NULL AS "accessibilite",
NULL::TEXT [] AS "labels_nationaux",
NULL::TEXT [] AS "labels_autres",
NULL::TEXT [] AS "thematiques",
typologie AS "typologie",
NULL AS "presentation_resume",
NULL AS "presentation_detail",
NULL AS "date_maj"
FROM structures_services
)

SELECT * FROM final
4 changes: 4 additions & 0 deletions pipeline/dbt/models/sources/cd39/_cd39__models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 2

models:
- name: stg_cd39__structures_services
27 changes: 27 additions & 0 deletions pipeline/dbt/models/sources/cd39/stg_cd39__structures_services.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
WITH source AS (
SELECT * FROM {{ source('cd39', 'structures_services') }}
),


final AS (
SELECT
_di_source_id AS "_di_source_id",
data ->> 'structure_id' AS "structure_id",
data ->> 'id_service' AS "id_service",
data ->> 'nom_structure' AS "nom_structure",
data ->> 'typologie' AS "typologie",
data ->> 'courriel_structure' AS "courriel_structure",
data ->> 'code_postal' AS "code_postal",
data ->> 'commune' AS "commune",
data ->> 'adresse' AS "adresse",
data ->> 'profils' AS "profils",
data ->> 'nom_service' AS "nom_service",
data ->> 'presentation_detail' AS "presentation_detail",
data ->> 'thematiques' AS "thematiques",
data ->> 'site_web' AS "site_web",
data ->> 'courriel_service' AS "courriel_service",
data ->> 'telephone' AS "telephone"
FROM source
)

SELECT * FROM final

0 comments on commit c495a91

Please sign in to comment.