From b3735a9820d1e9197c2af28ceec8eb5ecfcf5889 Mon Sep 17 00:00:00 2001 From: "Alexis A." Date: Thu, 14 Nov 2024 21:22:35 +0100 Subject: [PATCH] feat(epci_ept): remove duplication --- .../sql/sparte/models/admin_express/epci.sql | 29 +------------- .../models/admin_express/epci_tout_type.sql | 38 +++++++++++++++++++ .../sql/sparte/models/admin_express/ept.sql | 29 +------------- 3 files changed, 40 insertions(+), 56 deletions(-) create mode 100644 airflow/include/sql/sparte/models/admin_express/epci_tout_type.sql diff --git a/airflow/include/sql/sparte/models/admin_express/epci.sql b/airflow/include/sql/sparte/models/admin_express/epci.sql index c46b09e2d..a7a363f17 100644 --- a/airflow/include/sql/sparte/models/admin_express/epci.sql +++ b/airflow/include/sql/sparte/models/admin_express/epci.sql @@ -8,31 +8,4 @@ {'columns': ['geom'], 'type': 'gist'} ]) }} -with together as ( - SELECT - *, - 32620 AS srid_source - FROM {{ ref('epci_guadeloupe') }} - UNION ALL - SELECT - *, - 32620 AS srid_source - FROM {{ ref('epci_martinique') }} - UNION ALL - SELECT - *, - 2972 AS srid_source - FROM {{ ref('epci_guyane') }} - UNION ALL - SELECT - *, - 2975 AS srid_source - FROM {{ ref('epci_reunion') }} - UNION ALL - SELECT - *, - 2154 AS srid_source - FROM {{ ref('epci_metropole') }} -) -SELECT * FROM together -WHERE is_ept = false +SELECT * FROM {{ ref('epci_tout_type') }} WHERE is_ept = false diff --git a/airflow/include/sql/sparte/models/admin_express/epci_tout_type.sql b/airflow/include/sql/sparte/models/admin_express/epci_tout_type.sql new file mode 100644 index 000000000..c46b09e2d --- /dev/null +++ b/airflow/include/sql/sparte/models/admin_express/epci_tout_type.sql @@ -0,0 +1,38 @@ +{{ + config( + materialized='table', + indexes=[ + {'columns': ['id'], 'type': 'btree'}, + {'columns': ['code'], 'type': 'btree'}, + {'columns': ['name'], 'type': 'btree'}, + {'columns': ['geom'], 'type': 'gist'} + ]) +}} +with together as ( + SELECT + *, + 32620 AS srid_source + FROM {{ ref('epci_guadeloupe') }} + UNION ALL + SELECT + *, + 32620 AS srid_source + FROM {{ ref('epci_martinique') }} + UNION ALL + SELECT + *, + 2972 AS srid_source + FROM {{ ref('epci_guyane') }} + UNION ALL + SELECT + *, + 2975 AS srid_source + FROM {{ ref('epci_reunion') }} + UNION ALL + SELECT + *, + 2154 AS srid_source + FROM {{ ref('epci_metropole') }} +) +SELECT * FROM together +WHERE is_ept = false diff --git a/airflow/include/sql/sparte/models/admin_express/ept.sql b/airflow/include/sql/sparte/models/admin_express/ept.sql index 2c8e37f93..b5e41c20a 100644 --- a/airflow/include/sql/sparte/models/admin_express/ept.sql +++ b/airflow/include/sql/sparte/models/admin_express/ept.sql @@ -8,31 +8,4 @@ {'columns': ['geom'], 'type': 'gist'} ]) }} -with together as ( - SELECT - *, - 32620 AS srid_source - FROM {{ ref('epci_guadeloupe') }} - UNION ALL - SELECT - *, - 32620 AS srid_source - FROM {{ ref('epci_martinique') }} - UNION ALL - SELECT - *, - 2972 AS srid_source - FROM {{ ref('epci_guyane') }} - UNION ALL - SELECT - *, - 2975 AS srid_source - FROM {{ ref('epci_reunion') }} - UNION ALL - SELECT - *, - 2154 AS srid_source - FROM {{ ref('epci_metropole') }} -) -SELECT * FROM together -WHERE is_ept = true +SELECT * FROM {{ ref('epci_tout_type') }} WHERE is_ept = true