Skip to content

Commit

Permalink
[TO_SQUASH] fix following review
Browse files Browse the repository at this point in the history
  • Loading branch information
vperron committed Oct 29, 2024
1 parent 93130a8 commit ca6277e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
12 changes: 7 additions & 5 deletions pipeline/dags/notify_rgpd_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def _sync_new_contacts_to_brevo():
sql=(
"""
SELECT
json_build_object('email', _courriel_original),
rgpd_notice_has_hardbounced
FROM public_intermediate.int__union_contacts__enhanced
GROUP BY _courriel_original, rgpd_notice_has_hardbounced
ORDER BY _courriel_original
json_build_object('email', our_contacts.courriel),
brevo_contacts.has_hardbounced
FROM public_intermediate.int__union_contacts AS our_contacts
LEFT JOIN public_intermediate.int_brevo__contacts AS brevo_contacts
ON our_contacts.courriel = brevo_contacts.courriel
GROUP BY our_contacts.courriel, brevo_contacts.has_hardbounced
ORDER BY our_contacts.courriel
"""
)
)
Expand Down
6 changes: 3 additions & 3 deletions pipeline/dbt/models/intermediate/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ models:
- name: int__union_contacts__enhanced
columns:
- name: _di_surrogate_id
- name: _courriel_original
- name: id
- name: source
- name: contact_nom_prenom
Expand Down Expand Up @@ -245,10 +244,11 @@ unit_tests:
- {"source": "autre", "id": "solo", "courriel": "[email protected]", "contact_nom_prenom": "Autre Personne", "telephone": "06666666"}
- input: ref('int_brevo__contacts')
rows:
# note: values can't be NULL. has_hardbounced is set to true/false by brevo, and was_objected to is set to true/false by us.
- {"courriel": "[email protected]", "has_hardbounced": true, "was_objected_to": true}
- {"courriel": "[email protected]", "has_hardbounced": false, "was_objected_to": true}
- {"courriel": "[email protected]", "has_hardbounced": false, "was_objected_to": null}
- {"courriel": "[email protected]", "has_hardbounced": true, "was_objected_to": null}
- {"courriel": "[email protected]", "has_hardbounced": false, "was_objected_to": false}
- {"courriel": "[email protected]", "has_hardbounced": true, "was_objected_to": false}
expect:
rows:
- {source: dora, id: foo, courriel: NULL, contact_nom_prenom: NULL, telephone: NULL} # objected to, hardbounce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ WITH contacts AS (

final AS (
SELECT
id AS "id",
email AS "courriel",
email_blacklisted AS "has_hardbounced",
date_di_rgpd_opposition IS NOT NULL AS "was_objected_to"
id AS "id",
email AS "courriel",
email_blacklisted AS "has_hardbounced",
date_di_rgpd_opposition IS NOT NULL AS "was_objected_to"
FROM contacts
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ rgpd_notices AS (
SELECT
courriel,
has_hardbounced,
was_objected_to,
was_objected_to IS TRUE AS was_objected_to_truthy,
has_hardbounced IS TRUE AS has_hardbounced_truthy
was_objected_to
FROM {{ ref('int_brevo__contacts') }}
),

Expand All @@ -17,23 +15,22 @@ final AS (
contacts.source || '-' || contacts.id AS "_di_surrogate_id",
contacts.id AS "id",
contacts.source AS "source",
contacts.courriel AS "_courriel_original",
CASE
WHEN
rgpd_notices.courriel IS NULL
OR NOT rgpd_notices.was_objected_to_truthy
OR NOT rgpd_notices.was_objected_to
THEN contacts.contact_nom_prenom
END AS "contact_nom_prenom",
CASE
WHEN
rgpd_notices.courriel IS NULL
OR (NOT rgpd_notices.was_objected_to_truthy AND NOT rgpd_notices.has_hardbounced_truthy)
OR (NOT rgpd_notices.was_objected_to AND NOT rgpd_notices.has_hardbounced)
THEN contacts.courriel
END AS "courriel",
CASE
WHEN
rgpd_notices.courriel IS NULL
OR NOT rgpd_notices.was_objected_to_truthy
OR NOT rgpd_notices.was_objected_to
THEN contacts.telephone
END AS "telephone",
rgpd_notices.was_objected_to AS "rgpd_notice_was_objected_to",
Expand Down

0 comments on commit ca6277e

Please sign in to comment.