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

Be able to !include external yaml files #1790

Closed
whisperstream opened this issue Sep 27, 2019 · 14 comments
Closed

Be able to !include external yaml files #1790

whisperstream opened this issue Sep 27, 2019 · 14 comments
Labels
enhancement New feature or request stale Issues that have gone stale

Comments

@whisperstream
Copy link

Describe the feature

Sometimes its useful to reuse yaml (especially the schema.yml sections relating to docs). In my case, I have tables in different schemas and sometimes I have a view to the same table (except with different permissions). Ultimately though the view is just a select * from table_xyz, so the docs are the same. I don't want to have to maintain the documentation twice, and would prefer just to link to it.

The quick way to do this would be to allow external file linking as described here (https://stackoverflow.com/questions/528281/how-can-i-include-a-yaml-file-inside-another)

This is transparent to dbt and handled by the yaml loader.

Describe alternatives you've considered

Duplicating the documentation

Additional context

Who will this benefit?

Anyone who wants to reuse parts of their yaml files

@whisperstream whisperstream added enhancement New feature or request triage labels Sep 27, 2019
@drewbanin drewbanin removed the triage label Sep 27, 2019
@drewbanin
Copy link
Contributor

This is a cool idea, thanks @whisperstream! dbt does funky things with file paths, but I bet there's a way to make this work :)

@drewbanin
Copy link
Contributor

For this particular use-case, check out docs blocks if you haven't already. You'll still need to enumerate the columns for each model, but you can reference the docs blocks instead of re-typing the table/column descriptions.

Additionally, you may be able to use yaml anchors if you're able to define the docs for both of these models in the same file.

@whisperstream
Copy link
Author

have used the docs blocks already and have used yaml anchors before, but let me make a PR and test out the include and see how dbt gets on with it and you can decide to merge or not?

@drewbanin
Copy link
Contributor

sure, sounds good! Full disclosure, we might not merge this in the near-term -- we in general try to be careful about allowing arbitrary file access in the dbt context. There are things we can do here that may assuage this concern, so sure, I'd love to see a PR if you're able to send one through :)

@laxjesse
Copy link
Contributor

similar but different use case: I was hoping to be able to reference a non-schema.yml yaml file in a model.sql context to take advantage of the fromyaml context method.

I basically have a model that looks like this

{% set my_yml_str -%}
test1:
  - eligibility_start_criteria: some business logic
    eligibility_end_criteria: some more business logic
test2:
  - eligibility_start_criteria: more business logic
    eligibility_end_criteria: moar biz logic
goes on for a while ...
{%- endset %}

{% set my_dict = fromyaml(my_yml_str) %}
select
{% for item, criteria in my_dict.items() %}
  '{{ item }}' as group,
  {{ criteria[0]['eligibility_start_criteria'] }} as eligibility_start_criteria,
  {{ criteria[0]['eligibility_end_criteria'] }} as eligibility_end_criteria
{% endfor %}
from test

and was thinking it would be good to be able to maintain my_yml_str in a separate .yml file rather than in the model itself

@mrshu
Copy link

mrshu commented Jan 29, 2021

@drewbanin unless @whisperstream has already put a PR together, would you still be interested in seeing one?

I believe the ability to !include specific parts of .yml files could make them much more manageable (and in turn helps mitigate some of the standard complaints).

Thanks!

@github-actions
Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Dec 14, 2021
@mrshu
Copy link

mrshu commented Dec 16, 2021

Well, it's been a while and it seems like this issue will get closed in a few days, so let me just summarize what I think could be done here.

  • Much of YAML processing passes through safe_load, which in turn makes use of SafeLoader
  • The SafeLoader could be extended to support !include similar to the answer in https://stackoverflow.com/a/9577670
  • This would in turn make it so the fromyaml (but also basically any YAML string processed by dbt) gets the ability to !include other YAML files

Going by @drewbanin's comment above, I am still not sure to what extent does it make sense to try to implement this but if it sounds feasible, I might still take a stab at it at some point 🙂

Thanks!

@github-actions
Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Jun 18, 2022
@github-actions
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest; add a comment to notify the maintainers.

@mingfang
Copy link

please reopen

@databius
Copy link

It's useful to reuse yaml, please reopen

@ricklamps
Copy link

Please reopen! Being able to !include yaml files is very useful. The use case I'm thinking of is separating the source.yml file into many files, one per table, and !includeing them in the main source.yml file. If there's a better way to do this please let me know

@databius
Copy link

There is a new ticket with similar content: #9695

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

No branches or pull requests

7 participants