How do I create dynamic models getting information on source tables and target tables from a metadata table using the same jinja code?
I tried running below code but the config() does not seem to be working
{% if execute %}
{% set table_mappings1 = run_query(‘select source from x’).columns[0].values() %}
{% endif %}
{% if execute %}
{% set table_mappings2 = run_query(‘select target from x’).columns[0].values() %}
{% endif %}
{% for c1,c2 in zip(table_mappings1,table_mappings2) %}
{{config(materialized=‘table’, alias=‘{{c2}}’)}}
select * from {{c1}}
{% endfor %}
I think the challenge is that jinja will pull it back but you need to run what you pull back to build a usable/runnable model …?
We did something like this but instead of using jinja we used python to read from the table and build a set of model files based on a set of rules on how and what it read from the table. Run the python to build the models dynamically and then they can be run just as any other model. Using jinja to build the model and then render the model into a usable file was a path we looked at but were not able to accomplish.