Skip to content

Commit 419fdf0

Browse files
vperronYannickPassa
authored andcommitted
fix: Use internal macro pilo_star as a workaround for star()
While waiting for dbt_utils.star() to be fixed with dbt-labs/dbt-utils#732, we will use this proxy macro to not having to repeat the tedious if/else in all of our scripts.
1 parent d0eff65 commit 419fdf0

12 files changed

+29
-67
lines changed

dbt/macros/pilo_star.sql

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% macro pilo_star(table_name, relation_alias=False, except=[], prefix='', suffix='', quote_identifiers=True) -%}
2+
/* FIXME(vperron): Normally, sqlfluff rendering star() should render a `*`.
3+
But for some reason it does not, yet, or not anymore.
4+
https://github.com/dbt-labs/dbt-utils/pull/732
5+
In the meantime, and since we don't want to fully maintain an intialized DB in CI,
6+
we have to workaround it. I would have like to monkeypatch it in CI (some override of
7+
the macro somewhere) but could not find a way to do it. Essentialy, we would want the
8+
following code being applied automatically. */
9+
{%- if env_var('CI', '') -%}
10+
id
11+
{%- else -%}
12+
{{ dbt_utils.star(table_name, relation_alias, except, prefix, suffix, quote_identifiers) }}
13+
{%- endif -%}
14+
{% endmacro %}
15+

dbt/models/marts/candidats_auto_prescription.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id,
4-
{% else %}
5-
{{ dbt_utils.star(ref('stg_candidats_autoprescription'), relation_alias="autopr_c") }},
6-
{% endif %}
2+
{{ pilo_star(ref('stg_candidats_autoprescription'), relation_alias="autopr_c") }},
73
ac.total_candidats,
84
s.nom_structure_complet as "nom_structure_complet"
95
from
+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id
4-
{% else %}
5-
{{ dbt_utils.star(ref('candidatures_echelle_locale')) }}
6-
{% endif %}
2+
{{ pilo_star(ref('candidatures_echelle_locale')) }}
73
from {{ ref('candidatures_echelle_locale') }}
84
where "type_org_prescripteur" in ('CHRS', 'CHU', 'RS_FJT', 'OIL')

dbt/models/marts/candidatures_echelle_locale.sql

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id,
4-
{% else %}
5-
{{ dbt_utils.star(ref('stg_candidatures'), relation_alias='candidatures') }},
6-
{{ dbt_utils.star(ref('stg_org_prescripteur'), except=["id_org"], relation_alias='org_prescripteur') }},
7-
{{ dbt_utils.star(ref('stg_bassin_emploi'),
8-
except=["nom_departement", "nom_region", "type_epci", "id_structure"], relation_alias='bassin_emploi') }},
9-
{{ dbt_utils.star(ref('stg_reseaux'), except=["SIRET","id_structure"], relation_alias='rsx') }},
10-
{% endif %}
2+
{{ pilo_star(ref('stg_candidatures'), relation_alias='candidatures') }},
3+
{{ pilo_star(ref('stg_org_prescripteur'), except=["id_org"], relation_alias='org_prescripteur') }},
4+
{{ pilo_star(ref('stg_bassin_emploi'), except=["nom_departement", "nom_region", "type_epci", "id_structure"], relation_alias='bassin_emploi') }},
5+
{{ pilo_star(ref('stg_reseaux'), except=["SIRET","id_structure"], relation_alias='rsx') }},
116
case
127
when candidatures.injection_ai = 0 then 'Non'
138
else 'Oui'
+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id
4-
{% else %}
5-
{{ dbt_utils.star(ref('stg_organisations')) }}
6-
{% endif %}
2+
{{ pilo_star(ref('stg_organisations')) }}
73
from {{ ref('stg_organisations') }}
84
where type in ('CHRS', 'CHU', 'RS_FJT', 'OIL')

dbt/models/marts/reseaux.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id
4-
{% else %}
5-
{{ dbt_utils.star(ref('stg_reseaux')) }}
6-
{% endif %}
2+
{{ pilo_star(ref('stg_reseaux')) }}
73
from
84
{{ ref('stg_reseaux') }}

dbt/models/marts/suivi_auto_prescription.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
select
2-
{% if env_var('CI', '') %}
3-
autopr_all.*,
4-
{% else %}
5-
{{ dbt_utils.star(ref('stg_candidatures_autoprescription')) }},
6-
{% endif %}
2+
{{ pilo_star(ref('stg_candidatures_autoprescription')) }},
73
s.siret as siret,
84
s.active as active,
95
s.ville as ville,

dbt/models/marts/suivi_candidatures_prescripteurs_habilites.sql

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
with candidatures_ph as (
22
select
3-
/* FIXME(vperron): Normally, sqlfluff rendering star() should render a `*`.
4-
But for some reason it does not, yet, or not anymore.
5-
https://github.com/dbt-labs/dbt-utils/pull/732
6-
In the meantime, and since we don't want to fully maintain an intialized DB in CI,
7-
we have to workaround it. I would have like to monkeypatch it in CI (some override of
8-
the macro somewhere) but could not find a way to do it. Essentialy, we would want the
9-
following code being applied automatically. */
10-
{% if env_var('CI', '') %}
11-
*,
12-
{% else %}
13-
{{ dbt_utils.star(ref('candidatures_echelle_locale')) }},
14-
{% endif %}
3+
{{ pilo_star(ref('candidatures_echelle_locale')) }},
154
replace("origine_détaillée", 'Prescripteur habilité ', '') as origine_simplifiee
165
from {{ ref('candidatures_echelle_locale') }}
176
where starts_with("origine_détaillée", 'Prescripteur habilité')

dbt/models/staging/stg_candidats_autoprescription.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
select distinct
2-
{% if env_var('CI', '') %}
3-
id,
4-
{% else %}
5-
{{ dbt_utils.star(source('emplois', 'candidats'), relation_alias="c") }},
6-
{% endif %}
2+
{{ pilo_star(source('emplois', 'candidats'), relation_alias="c") }},
73
cd."état",
84
cd.nom_structure,
95
cd.type_structure,

dbt/models/staging/stg_candidatures.sql

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id,
4-
{% else %}
5-
{{ dbt_utils.star(source('emplois', 'candidatures'),
6-
except=["état", "motif_de_refus", "origine", "délai_de_réponse", "délai_prise_en_compte"]) }},
7-
{% endif %}
2+
{{ pilo_star(source('emplois', 'candidatures'), except=["état", "motif_de_refus", "origine", "délai_de_réponse", "délai_prise_en_compte"]) }},
83
case
94
when "état" = 'Candidature déclinée' then 'Candidature refusée'
105
else "état"

dbt/models/staging/stg_organisations.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
select
2-
{% if env_var('CI', '') %}
3-
id,
4-
{% else %}
5-
{{ dbt_utils.star(source('emplois', 'organisations')) }},
6-
{% endif %}
2+
{{ pilo_star(source('emplois', 'organisations')) }},
73
case
84
when "habilitée" = 1 then concat('Prescripteur habilité ', "type")
95
when "habilitée" = 0 then concat('Orienteur ', "type")

dbt/models/staging/stg_reseaux.sql

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
select
2-
{% if env_var('CI', '') %}
3-
siret,
4-
{% else %}
5-
{{ dbt_utils.star(source('oneshot', 'reseau_iae_adherents')) }},
6-
{% endif %}
2+
{{ pilo_star(source('oneshot', 'reseau_iae_adherents')) }},
73
s.id as id_structure,
84
rid.id_institution
95
from {{ source('oneshot', 'reseau_iae_adherents') }} as ria

0 commit comments

Comments
 (0)