-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
dbt extensions / dbt jinja extensions #3830
Comments
@jpeak-intellify Thanks for opening! It's a really solid thought, and I hope we can kick off some cool discussion. Big ideaAs we continue to solidify the foundations of
So, why not the Jinja context, too? I think there are two different ways to plug into / extend the syntax and functionality available in the dbt-Jinja templating context:
Are you thinking more about turning on extensions that are installed along with My concerns:
Specific use case
This is a more specific to dbt functionality—I totally hear you, and I think there's a pretty neat way we can enable this! There's a detailed proposal (#3456) to specify # dbt_project.yml
dispatch:
- macro_namespace: dbt
search_order: ['current_root_project', 'my_package_with_custom_macro_logic', 'dbt'] Whenever dbt goes to resolve a "global" macro, it would look for candidate implementations (prefixed Your issue prompted me to actually give this a go, which I did over in #3851. I think it might... just... work :) Now, to work for a specific global macro, that macro needs to be dispatched, and the Having said all that, I'm actually quite curious to hear about how you were planning to accomplish the above with Jinja extensions. |
Thanks @jtcohen6 for the comprehensive context catchup. Big IdeasIt seems like overall we are on the same page about a larger scope of work about the extensibility of dbt-core which is why I referenced pytest as prior art. dbt (in my mind) sits in a similar space that codifies the backbone of a common process. dbt seems to have solved a problem for 80-90% of people, but you've given the enterprises that have been datawarehousing for decades a teaser of a better future. A future where the gap between the sophistication of the tool and the complexity of the data modelling are not matched and in honesty that gap is a bit too enterprise specific. Really awesome reading through the list of points of extension (that look like to hooks I was trying to find) that allow enterprises to do their too specific quirks. Specific use caseMy specific problem is:
My poor assumptionI think I naively went down the route thinking I am constrained to the Jinja2 environment and blindly suggested trying to gain access to modify the Jinja2 environment. After looking at some Jinja extensions I am not confident it would achieve what I am after, and if it did, I'm not confident the person following me would be able to maintain that extension. So that was a bad idea in hindsight... Custom macro namespace precedence:The following
This would allow us to refactor our database and schema naming conventions into a dbt package and evolve them independently. Our consumer dbt projects would know that our flavour of macros have higher precedence. Minor concern:My only concern is that it is using Ideal outcome:My ideal outcome is that we have our own BigCorp flavoured dbt package
packages:
- git: "[email protected]:bigcorp/dbt-bigcorp-macros.git"
revision: vX.Y.Z Then it sounds like we would just create a dispatch namespace for them:
{% macro bigcorp__generate_schema_name(custom_schema_name, node) -%}
...
{% endmacro %}
{% macro bigcorp__generate_database_name(custom_database_name=none, node=none) -%}
...
{% endmacro %} Then if I understand correctly, opting into custom ordering would add the following to
dispatch:
- macro_namespace: dbt
search_order: ['my_root_project', 'bigcorp', 'dbt'] This would solve a whole class of problems for us, getting predictable behaviour when adopting our own flavour of conventions that deviate from the default dbt training modules. Next steps?
How does that sound? |
@jpeak-intellify Thanks for the detailed follow-up, and for engaging with the multiplicity of thoughts I threw your way. I think you've understood the dispatch strategy quite well; I just want to clarify a few points. You're right that the primary historical purpose of So the syntax of
The workflow we've been describing primarily depends on the first piece, but you'll still need to prefix your macros with an adapter signifier (almost certainly -- dbt_bigcorp_macros/macros.sql
{% macro default__generate_schema_name(custom_schema_name, node) -%}
...
{% endmacro %}
{% macro default__generate_database_name(custom_database_name=none, node=none) -%}
...
{% endmacro %} The I get that the -- dbt_bigcorp_macros/macros.sql
{% macro spark__generate_schema_name(custom_schema_name, node) -%}
...
{% endmacro %}
{% macro trino__generate_schema_name(custom_schema_name, node) -%}
...
{% endmacro %}
{% macro default__generate_schema_name(custom_schema_name, node) -%}
...
{% endmacro %} Following your So, if that all still sounds okay to you, I'm going to:
|
Thanks for the clarifications about the use of dispatched namespaces. That makes sense that the macros are resolved statically at parse time. |
Describe the feature
As a dbt user I should be able to install extensions through
pip
such that I can:pip install dbt-ext-myextension
ORpip install dbt-jinja-ext-myextension
And the
dbt
cli autoloads these extensions similar to pytest allowing control of the event hooks and the Jinja environment for custom behaviour.Describe alternatives you've considered
I am trying to automate overriding the
generate_database_name
andgenerate_schema_name
macros but even if I install a dbt-package with my custom macro logic I still need to manually shim these macros in each repo.Additional context
N/A
Who will this benefit?
Power users that have an architecture or naming conventions dictated by business users that has outrun what dbt Out-Of-Box (OOB) can achieve.
Ideally allowing the Jinja environment to be extended would be an end goal here. It looks like the
do
command is already being used fromjinja2.ext.do
. https://github.com/dbt-labs/dbt/blob/develop/core/dbt/clients/jinja.py#L489My ideal UX/DX would be:
dbt-jinja-ext-myextension
.dbt
then uses theimport_metalib.distributions()
functionality likepluggy
does for autodiscovery.This leverages prior art for plugin design.
It is minimally invasive (leaving plugins for dbt event hooks as a separate scope of work).
It leverages the Jinja Extension community as the scope of what can be done.
Authoring a python extension better leverages python tooling to maintain that code than Jinja macros in a dbt package.
Are you interested in contributing this feature?
Happy to help contribute this feature. Wanted to discuss scope of work before starting work though to fit in the roadmap.
For reference I was a maintainer of
vcrpy
API testing library for 6 months in 2019.The text was updated successfully, but these errors were encountered: