You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have problems with using macro inside of dbt where.
I know that when you try to use one you will get error:
Encountered an error:
Compilation Error
Invalid generic test configuration given in ../../projects/xxx/dbt/models/xxx/schema.yaml:
The model_name.column_name column's "not_null" test references an undefined macro in its where configuration argument. The macro 'country_specific' is undefined.
Please note that the generic test configuration parser currently does not support using custom macros to populate configuration values
@: UnparsedNodeUpdate(original_file_path='../.....ne)
But WHY?
I do not see any logical explanation of such a behaviour.
Why I want to use macro in where?
Imagine I have view like this:
ID
value
country_cd
1
0.56
ES
2
0.98
ES
3
0.11
IT
4
0.54
IT
5
0.12
ES
6
null
IT
I have some ML pipeline that modifies\uses only part of the data that is annotated with given country code (this is dbt variable like ('ES','TW')). At the end of this pipeline I want to test if part of the data I was using is errorfree so I want to test if value is not_null:
- name: value
tests:
- not_null:
where: "{% if var('country_cd', None) %} country_cd in {{ var('country_cd') }} {% else %} 1=1 {% endif %}"
So when I run two pipelines, one for IT and second for ES, IT will fail because of null value, but ES will be okay.
And now imagine that I have multiple models and multiple columns that look like this:
Nice idea would be to just write simple macro to avoid copypaste code:
Encountered an error:
Compilation Error
Invalid generic test configuration given in ../../projects/xxx/dbt/models/xxx/schema.yaml:
The model_name.column_name column's "not_null" test references an undefined macro in its where configuration argument. The macro 'country_specific' is undefined.
Please note that the generic test configuration parser currently does not support using custom macros to populate configuration values
@: UnparsedNodeUpdate(original_file_path='../.....ne)
I also do not want to rewrite default tests just to use country_code:
{% test column_not_null_for_country(model, column_name) %}
select *
from {{ model }}
where
{% if var('country_cd', None) %}
country_cd in {{ var('country_cd') }}
and
{% endif %}
{{ column_name }} is null
{% endtest %}
Is there any reason not to use macros in where? Do u know sane workaround for this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I have problems with using macro inside of dbt where.
I know that when you try to use one you will get error:
But WHY?
I do not see any logical explanation of such a behaviour.
Why I want to use macro in where?
Imagine I have view like this:
I have some ML pipeline that modifies\uses only part of the data that is annotated with given country code (this is dbt variable like
('ES','TW')
). At the end of this pipeline I want to test if part of the data I was using is errorfree so I want to test if value is not_null:So when I run two pipelines, one for
IT
and second forES
,IT
will fail because ofnull
value, butES
will be okay.And now imagine that I have multiple models and multiple columns that look like this:
Nice idea would be to just write simple macro to avoid copypaste code:
But when you do this I get error:
I also do not want to rewrite default tests just to use country_code:
Is there any reason not to use macros in
where
? Do u know sane workaround for this?Beta Was this translation helpful? Give feedback.
All reactions