-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sudocuh): add competence urba for commune
- Loading branch information
Showing
6 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from airflow.decorators import dag, task | ||
from include.domain.container import Container | ||
from include.pools import DBT_POOL | ||
from include.utils import get_dbt_command_from_directory | ||
from pendulum import datetime | ||
|
||
URL = "https://api-aln.datahub.din.developpement-durable.gouv.fr/sudocuh/enquetes/ref/plan/communal/CSV?annee_cog=2024" | ||
|
||
|
||
@dag( | ||
start_date=datetime(2024, 1, 1), | ||
schedule="@once", | ||
catchup=False, | ||
doc_md=__doc__, | ||
max_active_runs=1, | ||
default_args={"owner": "Alexis Athlani", "retries": 3}, | ||
tags=["SUDOCUH"], | ||
) | ||
def ingest_plan_communal(): | ||
bucket_name = "airflow-staging" | ||
plan_communal_filename = "plan_communal.csv" | ||
table_name = "sudocuh_plan_communal" | ||
|
||
@task.python | ||
def download_plan_communal() -> str: | ||
return ( | ||
Container() | ||
.remote_to_s3_file_handler() | ||
.download_http_file_and_upload_to_s3( | ||
url=URL, | ||
s3_key=plan_communal_filename, | ||
s3_bucket=bucket_name, | ||
) | ||
) | ||
|
||
@task.python | ||
def ingest_plan_communal() -> int | None: | ||
return ( | ||
Container() | ||
.s3_csv_file_to_db_table_handler() | ||
.ingest_s3_csv_file_to_db_table( | ||
s3_bucket=bucket_name, | ||
s3_key=plan_communal_filename, | ||
table_name=table_name, | ||
) | ||
) | ||
|
||
@task.bash(retries=0, trigger_rule="all_success", pool=DBT_POOL) | ||
def dbt_build(): | ||
return get_dbt_command_from_directory(cmd="dbt build -s sudocuh+") | ||
|
||
(download_plan_communal() >> ingest_plan_communal() >> dbt_build()) | ||
|
||
|
||
ingest_plan_communal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
airflow/include/sql/sparte/models/sudocuh/competence_plan_commune.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{ config(materialized='table') }} | ||
|
||
SELECT | ||
commune.code as commune_code, | ||
CASE | ||
WHEN code_etat_libelle_bcsi LIKE '%Compétence commune' THEN TRUE | ||
ELSE FALSE | ||
END AS competence_planification | ||
FROM | ||
{{ ref('commune') }} as commune | ||
LEFT JOIN | ||
{{ source('public', 'sudocuh_plan_communal') }} as plan_communal | ||
ON | ||
commune.code = plan_communal.code_insee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ sources: | |
tables: | ||
- name: sudocuh_scot | ||
- name: sudocuh_scot_communes | ||
- name: sudocuh_plan_communal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters