Skip to content

Commit 7bf65ab

Browse files
committed
dbt marts & dag airflow
1 parent 0d3f0e6 commit 7bf65ab

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

dbt/models/base/ban/base_ban_adresses.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ SELECT
1313
as it's a common suggestion filter */
1414
numero AS adresse_numero,
1515
nom_commune AS ville,
16-
nom_ancienne_commune AS ville_ancienne,
16+
/* We only keep ville_ancienne if it's different from current ville */
17+
CASE
18+
WHEN nom_ancienne_commune = nom_commune THEN NULL
19+
ELSE nom_ancienne_commune
20+
END AS ville_ancienne,
1721
code_postal,
1822
LEFT(code_postal, 2) AS code_departement,
1923
lat as latitude,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
post_hook = partial indexes on high-cardinality columns only for NOT NULL
3+
so we can still speed up the JOINS/FILTERS
4+
*/
5+
{{
6+
config(
7+
materialized = 'table',
8+
tags=['intermediate', 'ban', 'villes'],
9+
indexes=[
10+
{'columns': ['ville_ancienne']},
11+
{'columns': ['ville']},
12+
{'columns': ['code_postal']},
13+
{'columns': ['code_departement']},
14+
],
15+
post_hook=[
16+
"CREATE INDEX ON {{ this }}(ville_ancienne) WHERE ville_ancienne IS NOT NULL",
17+
]
18+
)
19+
}}
20+
21+
22+
SELECT
23+
ville_ancienne,
24+
ville,
25+
code_postal,
26+
code_departement
27+
FROM {{ ref('base_ban_adresses') }}
28+
GROUP BY 1,2,3,4
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{
2+
config(
3+
materialized = 'table',
4+
tags=['marts', 'enrich', 'ville','cities', 'ban'],
5+
)
6+
}}
7+
8+
SELECT
9+
acteurs.identifiant_unique AS acteur_id,
10+
acteurs.ville AS acteur_ville,
11+
acteurs.code_postal AS acteur_code_postal,
12+
ban.ville_ancienne AS ban_ville_ancienne,
13+
ban.ville AS ban_ville,
14+
ban.code_postal AS ban_code_postal,
15+
ban.ville AS remplacer_ville
16+
FROM {{ ref('marts_carte_acteur') }} AS acteurs
17+
JOIN {{ ref('int_ban_villes') }} AS ban ON ban.code_postal = acteurs.code_postal
18+
WHERE acteurs.statut = 'ACTIF'
19+
AND acteurs.code_postal IS NOT NULL and acteurs.code_postal != '' and LENGTH(acteurs.code_postal) = 5
20+
/* Only suggest if 1 difference */
21+
AND (
22+
acteurs.ville != ban.ville_ancienne
23+
OR acteurs.ville != ban.ville
24+
)
25+
/* BUT also a match somewhere */
26+
AND (
27+
udf_normalize_string_for_match(acteurs.ville,3) = udf_normalize_string_for_match(ban.ville_ancienne,3)
28+
OR udf_normalize_string_for_match(acteurs.ville,3) = udf_normalize_string_for_match(ban.ville,3)
29+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{
2+
config(
3+
materialized = 'view',
4+
alias = 'marts_enrich_acteurs_villes_suggest_new',
5+
tags=['marts', 'enrich', 'ville', 'ban','acteurs','nouvelle','new'],
6+
)
7+
}}
8+
9+
SELECT
10+
'acteurs_villes_anciennes_nouvelles' AS suggestion_cohorte_code,
11+
'🌆 Changement de ville: 🟡 ancienne -> nouvelle' AS suggestion_cohorte_label,
12+
*
13+
FROM {{ ref('marts_enrich_acteurs_villes_suggest') }}
14+
WHERE udf_normalize_string_for_match(acteur_ville,3) != udf_normalize_string_for_match(remplacer_ville,3)
15+
AND ban_ville_ancienne IS NOT NULL
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{
2+
config(
3+
materialized = 'view',
4+
alias = 'marts_enrich_acteurs_villes_suggest_typo',
5+
tags=['marts', 'enrich', 'ville', 'ban','acteurs','typo','ortographe'],
6+
)
7+
}}
8+
9+
SELECT
10+
'acteurs_villes_variation_ortographe' AS suggestion_cohorte_code,
11+
'🌆 Changement de ville: 🟢 variation d''ortographe' AS suggestion_cohorte_label,
12+
*
13+
FROM {{ ref('marts_enrich_acteurs_villes_suggest') }}
14+
WHERE udf_normalize_string_for_match(acteur_ville,3) = udf_normalize_string_for_match(remplacer_ville,3)
15+
AND ban_ville_ancienne IS NULL

0 commit comments

Comments
 (0)