dbt-datamocktool
dbt-datamocktool copied to clipboard
Ability to mock {{ this }} even when accessed inside macros
Describe the feature
Sometimes, in Incremental testing, we use call macros from a model to access {{ this }} table. In this case, the test fails to replace this table with the mock file
Describe alternatives you've considered
The alternative is completely to abandon the macro and have {{ this }} only in the model itself.
Additional context
Here is an example of the situation:
inside a block of {% if is_incremental %}
there might be a line like:
where id > (select max(column_name) from {{ this }})
but in other cases, we may just call a macro that does the same:
for example, we might implement it like this:
in the is_incremental block we write:
{% if is_incremental %}
{% set max_value = get_nax_value(column_name) %}
and then call:
where id > ('{{ max_value }}')
{% endif %}
the macro function get_max_value()
then implements select max(column_name) from {{ this }}
Problem is, that in compilation time this fails, because it tries to run the SELECT
statement in compile time in order to render the model, but the variable this
was not yet replaced by the mock table, because this happens only in runtime after rendering.
Who will this benefit?
Anyone who delegate functions from the module that uses {{ this }} into a macro
Are you interested in contributing this feature?
I would love to. Even though I do not have a suggestion on how to resolve it.
This would be very useful I think! I too have had issues / wanting this functionality.
Thanks @ran-silberman-gong and @pettersoderlund. I'm thinking about how to implement this. Let me know if you have some ideas, if not I'll update here soon!