From 6f59eb109b36ea3dd42e68b143acd4ca824cf9fb Mon Sep 17 00:00:00 2001 From: "Alexis A." Date: Thu, 19 Dec 2024 16:50:23 +0100 Subject: [PATCH] feat(rpls): remove duplicated lines --- .../sql/sparte/models/rpls/rpls_national.sql | 207 ++++++++---------- 1 file changed, 96 insertions(+), 111 deletions(-) diff --git a/airflow/include/sql/sparte/models/rpls/rpls_national.sql b/airflow/include/sql/sparte/models/rpls/rpls_national.sql index 3ae882769..783e90593 100644 --- a/airflow/include/sql/sparte/models/rpls/rpls_national.sql +++ b/airflow/include/sql/sparte/models/rpls/rpls_national.sql @@ -1,5 +1,76 @@ {{ config(materialized='table') }} +{% set paris = [ + '75101', + '75102', + '75103', + '75104', + '75105', + '75106', + '75107', + '75108', + '75109', + '75110', + '75111', + '75112', + '75113', + '75114', + '75115', + '75116', + '75117', + '75118', + '75119', + '75120' +] %} + +{% set lyon = [ + '69381', + '69382', + '69383', + '69384', + '69385', + '69386', + '69387', + '69388', + '69389' +] %} + +{% set marseille = [ + '13201', + '13202', + '13203', + '13204', + '13205', + '13206', + '13207', + '13208', + '13209', + '13210', + '13211', + '13212', + '13213', + '13214', + '13215', + '13216' +] %} + +{% set mayotte = [ + '97607', + '97611', + '97605', + '97614', + '97617', + '97610', + '97616', + '97609', + '97602', + '97608', + '97606', + '97603', + '97615', + '97604' +] %} + with raw_data as ( SELECT "Commune (DEP)" as commune_name, @@ -199,69 +270,19 @@ SELECT ) SELECT * FROM raw_data WHERE commune_code not in ( - -- Paris - '75101', - '75102', - '75103', - '75104', - '75105', - '75106', - '75107', - '75108', - '75109', - '75110', - '75111', - '75112', - '75113', - '75114', - '75115', - '75116', - '75117', - '75118', - '75119', - '75120', - -- Lyon - '69381', - '69382', - '69383', - '69384', - '69385', - '69386', - '69387', - '69388', - '69389', - -- Marseille - '13201', - '13202', - '13203', - '13204', - '13205', - '13206', - '13207', - '13208', - '13209', - '13210', - '13211', - '13212', - '13213', - '13214', - '13215', - '13216', - -- Mayotte - '97607', - '97611', - '97605', - '97614', - '97617', - '97610', - '97616', - '97609', - '97602', - '97608', - '97606', - '97603', - '97615', - '97604' + {% for code in paris %} + '{{ code }}', + {% endfor %} + {% for code in lyon %} + '{{ code }}', + {% endfor %} + {% for code in marseille %} + '{{ code }}', + {% endfor %} + {% for code in mayotte %} + '{{ code }}' + {% if not loop.last %},{% endif %} + {% endfor %} ) UNION SELECT @@ -273,27 +294,10 @@ SELECT FROM raw_data WHERE commune_code in ( - -- Paris - '75101', - '75102', - '75103', - '75104', - '75105', - '75106', - '75107', - '75108', - '75109', - '75110', - '75111', - '75112', - '75113', - '75114', - '75115', - '75116', - '75117', - '75118', - '75119', - '75120' + {% for code in paris %} + '{{ code }}' + {% if not loop.last %},{% endif %} + {% endfor %} ) UNION SELECT @@ -306,16 +310,10 @@ FROM raw_data WHERE commune_code in ( - -- Paris - '69381', - '69382', - '69383', - '69384', - '69385', - '69386', - '69387', - '69388', - '69389' + {% for code in lyon %} + '{{ code }}' + {% if not loop.last %},{% endif %} + {% endfor %} ) UNION SELECT @@ -327,21 +325,8 @@ SELECT FROM raw_data WHERE commune_code in ( - -- Marseille - '13201', - '13202', - '13203', - '13204', - '13205', - '13206', - '13207', - '13208', - '13209', - '13210', - '13211', - '13212', - '13213', - '13214', - '13215', - '13216' + {% for code in marseille %} + '{{ code }}' + {% if not loop.last %},{% endif %} + {% endfor %} )