From e81d717a7284f633fa1a82044a4788b7ff0eaab4 Mon Sep 17 00:00:00 2001 From: Victor Perron Date: Thu, 25 Jul 2024 18:12:57 +0200 Subject: [PATCH] __wip : Attempt a version of the stats without magic --- pipeline/dbt/macros/quality.sql | 73 +-- .../quality/int_quality__stats.sql | 494 ++++++++++++++++-- 2 files changed, 450 insertions(+), 117 deletions(-) diff --git a/pipeline/dbt/macros/quality.sql b/pipeline/dbt/macros/quality.sql index 0b6633bc3..e9a825006 100644 --- a/pipeline/dbt/macros/quality.sql +++ b/pipeline/dbt/macros/quality.sql @@ -1,72 +1,19 @@ -{% macro table_exists(model, schema, identifier) %} - {% set relation = adapter.get_relation( - database=model.database, - schema=schema or model.schema, - identifier=identifier or model.name) -%} - {% do return(relation is not none) %} +{% macro current_paris_date() %} + CURRENT_DATE AT TIME ZONE 'Europe/Paris' {% endmacro %} -{% macro stat_name(model) %} - {% set stat_name = model.schema ~ "_" ~ model.name ~ "_stats" -%} - {% do return(stat_name) %} +{% macro count_marts(source_slug, stream_kind) %} + SELECT COUNT(*) FROM public_marts.marts_inclusion__{{ stream_kind }} WHERE source = '{{ source_slug }}' {% endmacro %} -{% macro source_or_service(stream) %} - {% set mappings = ({ - "agences":"structure", - "aides":"service", - "benefits":"service", - "creches": "structure", - "DD009_RES_PARTENARIALE": "structure", - "etablissements": "structure", - "formations": "service", - "garages":"structure", - "institutions":"structure", - "lieux":"structure", - "organisations":"structure", - "siaes":"structure", - "services":"service", - "structures":"structure" - }) - -%} - {% set mapped_name = mappings.get(stream) -%} - {% do return(mapped_name) %} +{% macro count_api(source_slug, stream_kind) %} + SELECT COUNT(*) FROM public.api__{{ stream_kind }} WHERE source = '{{ source_slug }}' {% endmacro %} -{% macro intermediate_name(model) %} - {% set int_name = "int_" ~ model.schema ~ "__" ~ source_or_service(model.name) ~ "s" %} - {% do return(int_name) %} +{% macro count_contacts(source_slug, stream_kind) %} + SELECT COUNT(*) FROM public.api__{{ stream_kind }} WHERE source = '{{ source_slug }}' {% endmacro %} -{% macro source_stats(source) %} - {%- if not execute -%} - {{ return('') }} - {% endif -%} - {% set staging_name = "stg_" ~ source.schema ~ "__" ~ source.name %} - {% set intermediate_name = intermediate_name(source) %} - {% set stream_kind = source_or_service(source.name) %} - {% set source_slug = source.schema | replace("_", "-") %} - {{ stat_name(source) }} as ( - SELECT - CURRENT_DATE AT TIME ZONE 'Europe/Paris' as date, - '{{source.schema}}' as source, - '{{source.name}}' as stream, - COUNT(*) as count_raw, - {% if table_exists(source, "public_staging", staging_name) %} - (SELECT COUNT(*) FROM public_staging.{{ staging_name }}) as count_stg, - {% else %} - -1 as count_stg, - {% endif %} - {% if table_exists(source, "public_intermediate", intermediate_name) %} - (SELECT COUNT(*) FROM public_intermediate.{{ intermediate_name }}) as count_int, - {% else %} - -1 as count_int, - {% endif %} - (SELECT COUNT(*) FROM public_marts.marts_inclusion__{{ stream_kind }}s WHERE source = '{{ source_slug }}') as count_marts, - (SELECT COUNT(*) FROM public.api__{{ stream_kind }}s WHERE source = '{{ source_slug }}') as count_api, - (SELECT COUNT(*) FROM public.api__{{ stream_kind }}s WHERE source = '{{ source_slug }}' AND courriel IS NOT NULL AND telephone IS NOT NULL) as nb_contacts, - (SELECT COUNT(*) FROM public.api__{{ stream_kind }}s WHERE source = '{{ source_slug }}' AND (adresse IS NOT NULL OR commune IS NOT NULL OR code_postal IS NOT NULL or code_insee IS NOT NULL)) as nb_addresses - from - {{ source }} - ) +{% macro count_addresses(source_slug, stream_kind) %} + SELECT COUNT(*) FROM public.api__{{ stream_kind }} WHERE source = '{{ source_slug }}' {% endmacro %} diff --git a/pipeline/dbt/models/intermediate/quality/int_quality__stats.sql b/pipeline/dbt/models/intermediate/quality/int_quality__stats.sql index 4e77c35d1..6422af591 100644 --- a/pipeline/dbt/models/intermediate/quality/int_quality__stats.sql +++ b/pipeline/dbt/models/intermediate/quality/int_quality__stats.sql @@ -1,58 +1,444 @@ -/* -Removed providers. - -- finess & siao are not published in marts -- odspep is a special case -- the others are not "providers". -*/ -{% set excluded_schemas = [ - 'annuaire_du_service_public', - 'brevo', - 'finess', - 'insee', - 'odspep', - 'siao', - 'public' -] --%} - -/* Get sources as DBT objects, discarding some. */ -{% set sources = [] -%} -{% for node in graph.sources.values() -%} - {% if node.schema not in excluded_schemas -%} - {% set src = source(node.source_name, node.name) -%} - {%- if execute and table_exists(src) -%} - {%- do sources.append(src) -%} - {% endif -%} - {%- endif -%} -{%- endfor %} - -/* Adding manually the ODSPEP here isn't the greatest but it is - definitely the easiest way to have some info before too much - dirty code. - Issues: - - only considers the ODSPEP structures, not the services (cf. mapping in quality.sql) - - no info about the staging model -*/ -{% set sources = sources + [source('odspep', 'DD009_RES_PARTENARIALE')] -%} - -/* Get stats for each source */ -WITH {% for source in sources -%} - {%- if table_exists(source) -%} - {{- source_stats(source) -}} - {%- if not loop.last -%} - , {% endif -%} - {%- endif -%} -{%- endfor %}, +WITH data_inclusion_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'data_inclusion' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_data_inclusion__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_data_inclusion__structures') }}) AS count_int, + ({{ count_marts('data-inclusion', 'structures') }}) AS count_marts, + ({{ count_api('data-inclusion', 'structures') }}) AS count_api, + ({{ count_contacts('data-inclusion', 'structures') }}) AS count_contacts, + ({{ count_addresses('data-inclusion', 'structures') }}) AS count_addresses + FROM {{ source('data_inclusion_extra', 'structures') }} +), + +data_inclusion_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'data_inclusion' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_data_inclusion__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_data_inclusion__services') }}) AS count_int, + ({{ count_marts('data-inclusion', 'services') }}) AS count_marts, + ({{ count_api('data-inclusion', 'services') }}) AS count_api, + ({{ count_contacts('data-inclusion', 'services') }}) AS count_contacts, + ({{ count_addresses('data-inclusion', 'services') }}) AS count_addresses +), + +dora_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'dora' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_dora__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_dora__services') }}) AS count_int, + ({{ count_marts('dora', 'services') }}) AS count_marts, + ({{ count_api('dora', 'services') }}) AS count_api, + ({{ count_contacts('dora', 'services') }}) AS count_contacts, + ({{ count_addresses('dora', 'services') }}) AS count_addresses + FROM {{ source('dora', 'services') }} +), + +dora_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'dora' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_dora__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_dora__structures') }}) AS count_int, + ({{ count_marts('dora', 'structures') }}) AS count_marts, + ({{ count_api('dora', 'structures') }}) AS count_api, + ({{ count_contacts('dora', 'structures') }}) AS count_contacts, + ({{ count_addresses('dora', 'structures') }}) AS count_addresses + FROM {{ source('dora', 'structures') }} +), + +france_travail_agences_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'france_travail' AS source, + 'agences' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_france_travail__agences') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_france_travail__structures') }}) AS count_int, + ({{ count_marts('france-travail', 'structures') }}) AS count_marts, + ({{ count_api('france-travail', 'structures') }}) AS count_api, + ({{ count_contacts('france-travail', 'structures') }}) AS count_contacts, + ({{ count_addresses('france-travail', 'structures') }}) AS count_addresses + FROM {{ source('france_travail', 'agences') }} +), + +france_travail_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'france_travail' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_france_travail__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_france_travail__services') }}) AS count_int, + ({{ count_marts('france-travail', 'services') }}) AS count_marts, + ({{ count_api('france-travail', 'services') }}) AS count_api, + ({{ count_contacts('france-travail', 'services') }}) AS count_contacts, + ({{ count_addresses('france-travail', 'services') }}) AS count_addresses + FROM {{ source('france_travail', 'services') }} +), + +un_jeune_une_solution_benefits_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'un_jeune_une_solution' AS source, + 'benefits' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_un_jeune_une_solution__benefits') }}) AS count_stg, + 0 AS count_int, + 0 AS count_marts, + 0 AS count_api, + 0 AS count_contacts, + 0 AS count_addresses + FROM {{ source('un_jeune_une_solution', 'benefits') }} +), + +un_jeune_une_solution_institutions_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'un_jeune_une_solution' AS source, + 'institutions' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_un_jeune_une_solution__institutions') }}) AS count_stg, + 0 AS count_int, + 0 AS count_marts, + 0 AS count_api, + 0 AS count_contacts, + 0 AS count_addresses + FROM {{ source('un_jeune_une_solution', 'institutions') }} +), + +mes_aides_aides_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'mes_aides' AS source, + 'aides' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_mes_aides__aides') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_mes_aides__services') }}) AS count_int, + ({{ count_marts('mes-aides', 'services') }}) AS count_marts, + ({{ count_api('mes-aides', 'services') }}) AS count_api, + ({{ count_contacts('mes-aides', 'services') }}) AS count_contacts, + ({{ count_addresses('mes-aides', 'services') }}) AS count_addresses + FROM {{ source('mes_aides', 'aides') }} +), + +mes_aides_garages_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'mes_aides' AS source, + 'garages' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_mes_aides__garages') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_mes_aides__structures') }}) AS count_int, + ({{ count_marts('mes-aides', 'structures') }}) AS count_marts, + ({{ count_api('mes-aides', 'structures') }}) AS count_api, + ({{ count_contacts('mes-aides', 'structures') }}) AS count_contacts, + ({{ count_addresses('mes-aides', 'structures') }}) AS count_addresses + FROM {{ source('mes_aides', 'garages') }} +), + +cd35_organisations_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'cd35' AS source, + 'organisations' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_cd35__organisations') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_cd35__structures') }}) AS count_int, + ({{ count_marts('cd35', 'structures') }}) AS count_marts, + ({{ count_api('cd35', 'structures') }}) AS count_api, + ({{ count_contacts('cd35', 'structures') }}) AS count_contacts, + ({{ count_addresses('cd35', 'structures') }}) AS count_addresses + FROM {{ source('cd35', 'organisations') }} +), + +cd72_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'cd72' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_cd72__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_cd72__services') }}) AS count_int, + ({{ count_marts('cd72', 'services') }}) AS count_marts, + ({{ count_api('cd72', 'services') }}) AS count_api, + ({{ count_contacts('cd72', 'services') }}) AS count_contacts, + ({{ count_addresses('cd72', 'services') }}) AS count_addresses + FROM {{ source('cd72', 'services') }} +), + +cd72_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'cd72' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_cd72__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_cd72__structures') }}) AS count_int, + ({{ count_marts('cd72', 'structures') }}) AS count_marts, + ({{ count_api('cd72', 'structures') }}) AS count_api, + ({{ count_contacts('cd72', 'structures') }}) AS count_contacts, + ({{ count_addresses('cd72', 'structures') }}) AS count_addresses + FROM {{ source('cd72', 'structures') }} +), + +emplois_de_linclusion_organisations_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'emplois_de_linclusion' AS source, + 'organisations' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_emplois_de_linclusion__organisations') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_emplois_de_linclusion__structures') }}) AS count_int, + ({{ count_marts('emplois-de-linclusion', 'structures') }}) AS count_marts, + ({{ count_api('emplois-de-linclusion', 'structures') }}) AS count_api, + ({{ count_contacts('emplois-de-linclusion', 'structures') }}) AS count_contacts, + ({{ count_addresses('emplois-de-linclusion', 'structures') }}) AS count_addresses + FROM {{ source('emplois_de_linclusion', 'organisations') }} +), + +emplois_de_linclusion_siaes_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'emplois_de_linclusion' AS source, + 'siaes' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_emplois_de_linclusion__siaes') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_emplois_de_linclusion__structures') }}) AS count_int, + ({{ count_marts('emplois-de-linclusion', 'structures') }}) AS count_marts, + ({{ count_api('emplois-de-linclusion', 'structures') }}) AS count_api, + ({{ count_contacts('emplois-de-linclusion', 'structures') }}) AS count_contacts, + ({{ count_addresses('emplois-de-linclusion', 'structures') }}) AS count_addresses + FROM {{ source('emplois_de_linclusion', 'siaes') }} +), + +mediation_numerique_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'mediation_numerique' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_mediation_numerique__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_mediation_numerique__services') }}) AS count_int, + ({{ count_marts('mediation-numerique', 'services') }}) AS count_marts, + ({{ count_api('mediation-numerique', 'services') }}) AS count_api, + ({{ count_contacts('mediation-numerique', 'services') }}) AS count_contacts, + ({{ count_addresses('mediation-numerique', 'services') }}) AS count_addresses + FROM {{ source('mediation_numerique', 'services') }} +), + +mediation_numerique_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'mediation_numerique' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_mediation_numerique__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_mediation_numerique__structures') }}) AS count_int, + ({{ count_marts('mediation-numerique', 'structures') }}) AS count_marts, + ({{ count_api('mediation-numerique', 'structures') }}) AS count_api, + ({{ count_contacts('mediation-numerique', 'structures') }}) AS count_contacts, + ({{ count_addresses('mediation-numerique', 'structures') }}) AS count_addresses + FROM {{ source('mediation_numerique', 'structures') }} +), + +soliguide_lieux_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'soliguide' AS source, + 'lieux' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_soliguide__lieux') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_soliguide__structures') }}) AS count_int, + ({{ count_marts('soliguide', 'structures') }}) AS count_marts, + ({{ count_api('soliguide', 'structures') }}) AS count_api, + ({{ count_contacts('soliguide', 'structures') }}) AS count_contacts, + ({{ count_addresses('soliguide', 'structures') }}) AS count_addresses + FROM {{ source('soliguide', 'lieux') }} +), + +monenfant_creches_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'monenfant' AS source, + 'creches' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_monenfant__creches') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_monenfant__structures') }}) AS count_int, + ({{ count_marts('monenfant', 'structures') }}) AS count_marts, + ({{ count_api('monenfant', 'structures') }}) AS count_api, + ({{ count_contacts('monenfant', 'structures') }}) AS count_contacts, + ({{ count_addresses('monenfant', 'structures') }}) AS count_addresses + FROM {{ source('monenfant', 'creches') }} +), + +agefiph_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'agefiph' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_agefiph__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_agefiph__services') }}) AS count_int, + ({{ count_marts('agefiph', 'services') }}) AS count_marts, + ({{ count_api('agefiph', 'services') }}) AS count_api, + ({{ count_contacts('agefiph', 'services') }}) AS count_contacts, + ({{ count_addresses('agefiph', 'services') }}) AS count_addresses + FROM {{ source('agefiph', 'services') }} +), + +reseau_alpha_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'reseau_alpha' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_reseau_alpha__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_reseau_alpha__structures') }}) AS count_int, + ({{ count_marts('reseau-alpha', 'structures') }}) AS count_marts, + ({{ count_api('reseau-alpha', 'structures') }}) AS count_api, + ({{ count_contacts('reseau-alpha', 'structures') }}) AS count_contacts, + ({{ count_addresses('reseau-alpha', 'structures') }}) AS count_addresses + FROM {{ source('reseau_alpha', 'structures') }} +), + +reseau_alpha_formations_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'reseau_alpha' AS source, + 'formations' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_reseau_alpha__formations') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_reseau_alpha__services') }}) AS count_int, + ({{ count_marts('reseau-alpha', 'services') }}) AS count_marts, + ({{ count_api('reseau-alpha', 'services') }}) AS count_api, + ({{ count_contacts('reseau-alpha', 'services') }}) AS count_contacts, + ({{ count_addresses('reseau-alpha', 'services') }}) AS count_addresses + FROM {{ source('reseau_alpha', 'formations') }} +), + +fredo_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'fredo' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_fredo__structures') }}) AS count_stg, + 0 AS count_int, + 0 AS count_marts, + 0 AS count_api, + 0 AS count_contacts, + 0 AS count_addresses + FROM {{ source('fredo', 'structures') }} +), + +action_logement_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'action_logement' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_action_logement__structures') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_action_logement__structures') }}) AS count_int, + ({{ count_marts('action-logement', 'structures') }}) AS count_marts, + ({{ count_api('action-logement', 'structures') }}) AS count_api, + ({{ count_contacts('action-logement', 'structures') }}) AS count_contacts, + ({{ count_addresses('action-logement', 'structures') }}) AS count_addresses + FROM {{ source('action_logement', 'structures') }} +), + +action_logement_services_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'action_logement' AS source, + 'services' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_action_logement__services') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_action_logement__services') }}) AS count_int, + ({{ count_marts('action-logement', 'services') }}) AS count_marts, + ({{ count_api('action-logement', 'services') }}) AS count_api, + ({{ count_contacts('action-logement', 'services') }}) AS count_contacts, + ({{ count_addresses('action-logement', 'services') }}) AS count_addresses + FROM {{ source('action_logement', 'services') }} +), + +odspep_structures_stats AS ( + SELECT + {{ current_paris_date() }} AS compute_date, + 'odspep' AS source, + 'structures' AS stream, + COUNT(*) AS count_raw, + (SELECT COUNT(*) FROM {{ ref('stg_odspep__res_partenariales') }}) AS count_stg, + (SELECT COUNT(*) FROM {{ ref('int_odspep__structures') }}) AS count_int, + ({{ count_marts('odspep', 'structures') }}) AS count_marts, + ({{ count_api('odspep', 'structures') }}) AS count_api, + ({{ count_contacts('odspep', 'structures') }}) AS count_contacts, + ({{ count_addresses('odspep', 'structures') }}) AS count_addresses + FROM {{ source('odspep', 'DD009_RES_PARTENARIALE') }} +), + final AS ( - {%- for source in sources %} - {%- if table_exists(source) -%} - SELECT * FROM {{ stat_name(source) }} - {% if not loop.last -%} - UNION ALL - {% endif -%} - {%- endif %} - {%- endfor %} + SELECT * FROM data_inclusion_structures_stats + UNION ALL + SELECT * FROM data_inclusion_services_stats + UNION ALL + SELECT * FROM dora_structures_stats + UNION ALL + SELECT * FROM dora_services_stats + UNION ALL + SELECT * FROM france_travail_agences_stats + UNION ALL + SELECT * FROM france_travail_services_stats + UNION ALL + SELECT * FROM un_jeune_une_solution_institutions_stats + UNION ALL + SELECT * FROM un_jeune_une_solution_benefits_stats + UNION ALL + SELECT * FROM mes_aides_garages_stats + UNION ALL + SELECT * FROM mes_aides_aides_stats + UNION ALL + SELECT * FROM cd35_organisations_stats + UNION ALL + SELECT * FROM cd72_structures_stats + UNION ALL + SELECT * FROM cd72_services_stats + UNION ALL + SELECT * FROM emplois_de_linclusion_siaes_stats + UNION ALL + SELECT * FROM emplois_de_linclusion_organisations_stats + UNION ALL + SELECT * FROM mediation_numerique_structures_stats + UNION ALL + SELECT * FROM mediation_numerique_services_stats + UNION ALL + SELECT * FROM soliguide_lieux_stats + UNION ALL + SELECT * FROM monenfant_creches_stats + UNION ALL + SELECT * FROM agefiph_services_stats + UNION ALL + SELECT * FROM reseau_alpha_structures_stats + UNION ALL + SELECT * FROM reseau_alpha_formations_stats + UNION ALL + SELECT * FROM fredo_structures_stats + UNION ALL + SELECT * FROM action_logement_structures_stats + UNION ALL + SELECT * FROM action_logement_services_stats + UNION ALL + SELECT * FROM odspep_structures_stats ) SELECT * FROM final