From 641cbc549a18a9e1f2fae1f6c9427a4a3cf80b49 Mon Sep 17 00:00:00 2001 From: Hugo Lecuyer Date: Tue, 17 Sep 2024 11:43:49 +0200 Subject: [PATCH] fix(fredo): select first email from list --- .../intermediate/sources/fredo/int_fredo__structures.sql | 4 +++- .../models/staging/sources/fredo/stg_fredo__structures.sql | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pipeline/dbt/models/intermediate/sources/fredo/int_fredo__structures.sql b/pipeline/dbt/models/intermediate/sources/fredo/int_fredo__structures.sql index a66bb1b12..ca9d5fde9 100644 --- a/pipeline/dbt/models/intermediate/sources/fredo/int_fredo__structures.sql +++ b/pipeline/dbt/models/intermediate/sources/fredo/int_fredo__structures.sql @@ -52,7 +52,9 @@ final AS ( CASE WHEN ARRAY_LENGTH(structures.telephone, 1) > 0 THEN structures.telephone[1] END AS "telephone", - structures.courriel AS "courriel", + CASE + WHEN ARRAY_LENGTH(structures.courriel, 1) > 0 THEN structures.courriel[1] + END AS "courriel", structures.site_web AS "site_web", LEFT(structures.presentation_resume, 280) AS "presentation_resume", structures.presentation_resume AS "presentation_detail", diff --git a/pipeline/dbt/models/staging/sources/fredo/stg_fredo__structures.sql b/pipeline/dbt/models/staging/sources/fredo/stg_fredo__structures.sql index b7b12b802..bc6f1a21c 100644 --- a/pipeline/dbt/models/staging/sources/fredo/stg_fredo__structures.sql +++ b/pipeline/dbt/models/staging/sources/fredo/stg_fredo__structures.sql @@ -7,7 +7,6 @@ final AS ( _di_source_id AS "_di_source_id", data ->> 'id' AS "id", NULLIF(TRIM(data ->> 'adresse'), '') AS "adresse", - NULLIF(TRIM(data ->> 'email'), '') AS "courriel", NULLIF(TRIM(data ->> 'code_postal'), '') AS "code_postal", NULLIF(TRIM(data ->> 'commune'), '') AS "commune", NULLIF(TRIM(data ->> 'frais'), '') AS "frais", @@ -24,6 +23,11 @@ final AS ( THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'telephone')) AS TEXT []) ELSE CAST(NULL AS TEXT []) END AS "telephone", + CASE + WHEN data ->> 'email' IS NOT NULL + THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'email')) AS TEXT []) + ELSE CAST(NULL AS TEXT []) + END AS "courriel", CASE WHEN data ->> 'categories' IS NOT NULL THEN CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(data -> 'categories')) AS TEXT [])