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

[Feature] Allow jinja templating YML just like we can jinja template SQL #11077

Open
3 tasks done
siljamardla opened this issue Nov 30, 2024 · 0 comments
Open
3 tasks done
Labels
enhancement New feature or request triage

Comments

@siljamardla
Copy link

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.

@siljamardla siljamardla added enhancement New feature or request triage labels Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
Development

No branches or pull requests

1 participant