[Feature] Allow jinja templating YML just like we can jinja template SQL
Opened this issue · 0 comments
Is this your first time submitting a feature request?
- I have read the expectations for open source contributors
- I have searched the existing issues, and I could not find an existing issue for this feature
- I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
Describe the feature
To make our pipelines modular, we want to use intermediate models.
When intermediate models are in use and we want to properly document them, we end up duplicating a lot of YML between the intermediate model and the main model.
This would be greatly reduced if we were able to do something like this:
{% macro column_list() %}
[
{"name": "my_column_1", "description": "{{ doc('my_column_description_1') }}", "data_type": "INTEGER"},
{"name": "my_column_2", "description": "{{ doc('my_column_description_2') }}", "data_type": "INTEGER"},
{"name": "my_column_3", "description": "{{ doc('my_column_description_3') }}", "data_type": "INTEGER"},
{"name": "my_column_4", "description": "{{ doc('my_column_description_4') }}", "data_type": "INTEGER"},
{"name": "my_column_5", "description": "{{ doc('my_column_description_5') }}", "data_type": "INTEGER"}
]
{% endmacro %}
and
models:
- name: my_model
description: A dbt model with a bunch of columns
columns:
{% for column in column_list() %}
- name: {{ column.name }}
description: {{ column.description }}
data_type: {{ column.data_type }}
{% endfor %}
And, we could use the same list also in the main model SQL code (adjust a little to get the commas right):
SELECT
{% for column in column_list() %}
, {{ column.name }} :: {{ column.data_type }}
{% endfor %}
FROM {{ ref('my_int_model') }}
Describe alternatives you've considered
Manually maintain the same list of things in multiple places. Lots of copy-paste.
Who will this benefit?
Anyone who feels the pain of having to copy-paste lists of columns between models.
Are you interested in contributing this feature?
No response
Anything else?
Related feature request:
#9695
Essentially the same requirement, but a different approach to solving the problem.
Also, the outcome is somewhat different (being able to bulk import a block of YML vs being able to template places in your YML file).
I think the jinja way would be closer to how other things work in dbt.