Jinja statements from vars in schema.yml
See original GitHub issueDescribe the feature
Ability to use jinja loops inside schema yaml would really improve how generic things like sources
would be. For example:
Consider a situation where a package has an input of either a ref or a source, defined based on a var.
It would be nice to be able to accept a list of sources or refs that would that would be unioned together dynamically based on the entries in the var. For refs, it’s completely possible at the moment but for sources, it’s not possible to write jinja statements (such as if / for loops) in a schema.yml
file.
ie:
sources:
- name: my_source
tables:
{% for table_name in var('my_list_of_tables') %}
- name: "{{table_name}}"
{% endfor %}
Describe alternatives you’ve considered
Obviously a clear alternate is “dont allow this”, which definitely works. Unfortunately, for a source to be referenced, it needs to be defined in a schema yaml so I haven’t thought of any possible alternatives as of right now.
Who will this benefit?
Package developers
Are you interested in contributing this feature?
Happy to help out if I’m able to! I’m already on the hook for another issue that I’ve been dragging my feet on 😅
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Has jinja implementation been considered anymore in yml files?
I would like to make sure everything is documented correctly. If I have created a loop within my SQL code, then it would be very beneficial to be able to loop within the yml file too.
For example, it would be good to do something like the below:
instead of having to create the yml file manually like so:
Being able to create a loop helps massively if more variables are added (for example TIME_PERIODS in this case) and removes any possibility of undocumented variables.
@jtcohen6 Is there a way to do this dynamically? If I have a slowly-changing group of tables in a schema? For example, one day I have name: tbl_red, and the next day this table is gone? I would like to cycle through the tables in the schema and add these to the var 😃