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] - User Defined Macros & Filters #4872

Closed
1 task done
afranzi opened this issue Feb 8, 2024 · 5 comments
Closed
1 task done

[Feature] - User Defined Macros & Filters #4872

afranzi opened this issue Feb 8, 2024 · 5 comments
Labels
content Improvements or additions to content improvement Use this when an area of the docs needs improvement as it's currently unclear

Comments

@afranzi
Copy link

afranzi commented Feb 8, 2024

Contributions

  • I have read the contribution docs, and understand what's expected of me.

Link to the page on docs.getdbt.com requiring updates

Not sure if this would be part of the https://docs.getdbt.com/reference/project-configs/macro-paths
Or in https://docs.getdbt.com/reference/dbt-jinja-functions

What part(s) of the page would you like to see updated?

The main idea would be adding documentation about the new incoming feature allowing DBT developers to inject their own python JINJA macros and filters in addition to the native ones, so developers can move complex jinja templating code to python and level up their dbt projects with more possibilities.

Some examples:

  • Expand DBT credentials fetching them from a secret store (i.e. AWS Secrets Manager).
  • Enable models based on an external config (i.e. HTTP Requests to an external API which defines if the model can be enabled).
    by

We can enable this behavior by defining the following ENV vars with the path:instance format.

  • DBT_USER_DEFINED_MACROS: Jinja Macros
  • DBT_USER_DEFINED_FILTERS: Jinja Filters

Additional information

This documentation would be based on this PR dbt-labs/dbt-common#72.

See following example about how I've used it locally:

Screenshot 2024-02-08 at 11 12 05
Screenshot 2024-02-08 at 11 11 36
Screenshot 2024-02-08 at 11 11 14

@afranzi afranzi added content Improvements or additions to content improvement Use this when an area of the docs needs improvement as it's currently unclear labels Feb 8, 2024
@afranzi
Copy link
Author

afranzi commented Feb 8, 2024

Adding some examples about the credentials:
Screenshot 2024-02-08 at 11 51 31
Screenshot 2024-02-08 at 11 51 38
Screenshot 2024-02-08 at 11 52 08

@ismailsimsek
Copy link

created related discussion here dbt-labs/dbt-adapters#259

IMO Adapter factory should allow user provided customized adapter class. this will open door to customization

@ismailsimsek
Copy link

PR dbt-labs/dbt-adapters#261
implemented in this package https://github.com/memiiso/opendbt
example https://github.com/memiiso/opendbt/blob/main/docs/EXAMPLES.md#execute-python-model-locally

using @available decorator makes the function available to jinja

@matthewshaver
Copy link
Contributor

Attached PRs were closed, so closing this issue as well.

@afranzi
Copy link
Author

afranzi commented Dec 9, 2024

It's quite sad seeing DBT Labs taking this approach and closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content improvement Use this when an area of the docs needs improvement as it's currently unclear
Projects
None yet
Development

No branches or pull requests

3 participants