Skip to content

Commit

Permalink
fix(sqlfluff): fix sql linting config
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Nov 18, 2024
1 parent c49e571 commit 167b0c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 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",
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
2 changes: 1 addition & 1 deletion pipeline/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 167b0c7

Please sign in to comment.