Skip to content

Commit

Permalink
fix(sqlfluff): fix sql linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Nov 18, 2024
1 parent 0c492da commit 4b117fa
Showing 1 changed file with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(data -> 'thematiques', 'null'))))::TEXT [] AS "thematiques",
((data ->> 'longitude'))::FLOAT AS "longitude",
((data ->> 'latitude'))::FLOAT AS "latitude",
((data ->> 'date_maj'))::TIMESTAMP WITH TIME ZONE AS "date_maj",
source._di_source_id AS "_di_source_id",
(
ARRAY(
SELECT thematiques.*
FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(source.data -> 'thematiques', 'null')) AS thematiques
)
)::TEXT [] AS "thematiques",
((source.data ->> 'longitude'))::FLOAT AS "longitude",
((source.data ->> 'latitude'))::FLOAT AS "latitude",
((source.data ->> 'date_maj'))::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",
(
ARRAY(
SELECT labels_autres.*
FROM JSONB_ARRAY_ELEMENTS_TEXT(NULLIF(source.data -> 'labels_autres', 'null')) AS labels_autres
)
)::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

0 comments on commit 4b117fa

Please sign in to comment.