From 167b0c71d3af142ec79896744ab234a0304b6aa8 Mon Sep 17 00:00:00 2001 From: Hugo Lecuyer Date: Mon, 18 Nov 2024 10:41:25 +0100 Subject: [PATCH] fix(sqlfluff): fix sql linting config --- .../stg_mediation_numerique__structures.sql | 60 +++++++++++-------- pipeline/pyproject.toml | 2 +- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/pipeline/dbt/models/staging/sources/mediation_numerique/stg_mediation_numerique__structures.sql b/pipeline/dbt/models/staging/sources/mediation_numerique/stg_mediation_numerique__structures.sql index c199a467..aa86a3da 100644 --- a/pipeline/dbt/models/staging/sources/mediation_numerique/stg_mediation_numerique__structures.sql +++ b/pipeline/dbt/models/staging/sources/mediation_numerique/stg_mediation_numerique__structures.sql @@ -20,42 +20,52 @@ labels_nationaux AS ( FROM labels_nationaux_prep WHERE labels_nationaux IN ( - SELECT labels_nationaux."value" FROM labels_nationaux_seed + SELECT labels_nationaux_seed."value" FROM labels_nationaux_seed ) GROUP BY id ), final AS ( SELECT - _di_source_id AS "_di_source_id", - CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(data -> 'thematiques', 'null'))) AS TEXT []) AS "thematiques", - CAST((data ->> 'longitude') AS FLOAT) AS "longitude", - CAST((data ->> 'latitude') AS FLOAT) AS "latitude", - CAST((data ->> 'date_maj') AS TIMESTAMP WITH TIME ZONE) AS "date_maj", + source._di_source_id AS "_di_source_id", + CAST(( + ARRAY( + SELECT thematiques.* + FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(source.data -> 'thematiques', 'null')) AS thematiques + ) + ) AS TEXT []) AS "thematiques", + CAST((source.data ->> 'longitude') AS FLOAT) AS "longitude", + CAST((source.data ->> 'latitude') AS FLOAT) AS "latitude", + CAST((source.data ->> 'date_maj') AS TIMESTAMP WITH TIME ZONE) AS "date_maj", -- SOURCEFIX(2024-10-14) -- SOURCEFIX(2024-11-18) - labels_nationaux.labels_nationaux AS "labels_nationaux", - (ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(data -> 'labels_autres', 'null'))))::TEXT [] AS "labels_autres", - data ->> 'id' AS "id", - data ->> 'nom' AS "nom", - NULLIF(data ->> 'siret', REPEAT('0', 14)) AS "siret", - data ->> 'source' AS "source", - NULLIF(TRIM(data ->> 'adresse'), '') AS "adresse", - NULLIF(TRIM(data ->> 'commune'), '') AS "commune", - NULLIF(TRIM(data ->> 'courriel'), '') AS "courriel", - data ->> 'site_web' AS "site_web", - NULLIF(TRIM(data ->> 'telephone'), '') AS "telephone", - data ->> 'code_postal' AS "code_postal", - data ->> 'code_insee' AS "code_insee", - data ->> 'horaires_ouverture' AS "horaires_ouverture", - data ->> 'typologie' AS "typologie", - data ->> 'presentation_resume' AS "presentation_resume", - data ->> 'accessibilite' AS "accessibilite", - data ->> 'presentation_detail' AS "presentation_detail" + labels_nationaux.labels_nationaux AS "labels_nationaux", + CAST(( + ARRAY( + SELECT labels_autres.* + FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(source.data -> 'labels_autres', 'null')) AS labels_autres + ) + ) AS TEXT []) AS "labels_autres", + source.data ->> 'id' AS "id", + source.data ->> 'nom' AS "nom", + NULLIF(source.data ->> 'siret', REPEAT('0', 14)) AS "siret", + source.data ->> 'source' AS "source", + NULLIF(TRIM(source.data ->> 'adresse'), '') AS "adresse", + NULLIF(TRIM(source.data ->> 'commune'), '') AS "commune", + NULLIF(TRIM(source.data ->> 'courriel'), '') AS "courriel", + source.data ->> 'site_web' AS "site_web", + NULLIF(TRIM(source.data ->> 'telephone'), '') AS "telephone", + source.data ->> 'code_postal' AS "code_postal", + source.data ->> 'code_insee' AS "code_insee", + source.data ->> 'horaires_ouverture' AS "horaires_ouverture", + source.data ->> 'typologie' AS "typologie", + source.data ->> 'presentation_resume' AS "presentation_resume", + source.data ->> 'accessibilite' AS "accessibilite", + source.data ->> 'presentation_detail' AS "presentation_detail" FROM source LEFT JOIN labels_nationaux ON source.data ->> 'id' = labels_nationaux.id WHERE - data ->> 'source' != 'dora' + source.data ->> 'source' != 'dora' ) SELECT * FROM final diff --git a/pipeline/pyproject.toml b/pipeline/pyproject.toml index 88656749..9c89bc22 100644 --- a/pipeline/pyproject.toml +++ b/pipeline/pyproject.toml @@ -73,7 +73,7 @@ capitalisation_policy = "upper" [tool.sqlfluff.rules.convention.casting_style] # SQL type casting -preferred_type_casting_style = "shorthand" +preferred_type_casting_style = "cast" [tool.sqlfluff.templater.dbt] project_dir = "./pipeline/dbt"