Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to mock {{ this }} even when accessed inside macros #77

Open
ran-silberman-gong opened this issue May 16, 2023 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@ran-silberman-gong
Copy link

ran-silberman-gong commented May 16, 2023

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.

@ran-silberman-gong ran-silberman-gong added the enhancement New feature or request label May 16, 2023
@pettersoderlund
Copy link
Collaborator

This would be very useful I think! I too have had issues / wanting this functionality.

@mjirv
Copy link
Owner

mjirv commented Jun 4, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants