[CT-539] [Feature] Add zip
and modules.itertools
to BaseContext
#5130
Labels
enhancement
New feature or request
help_wanted
Trickier changes, with a clear starting point, good for previous/experienced contributors
Is there an existing feature request for this?
Describe the Feature
Add python's built-in
zip
function to the Jinja context for use like a global macro and select functions fromitertools
as accessible from themodules
variable.Describe alternatives you've considered
Attempt to manually replicate the functions as Jinja macros:
E.g. implementation of
itertools.product
:Who will this benefit?
This will benefit end-users, allowing more concise models and removing need to manually recreate such functionality (or import a package doing so).
For example, suppose we have 3 tables, and a list of their dimension fields:
Suppose I wish to generate a surrogate key based on all of these keys in the same model in which I'm joining them all together. Presently this can be accomplished with something like:
where
product
is a jinja macro with definition given above.With this proposed feature added to
dbt-core
, the same could be accomplished without having to add aproduct
macro and instead being able to do:or even enable one to go really crazy:
or if the
itertools
functions were implemented as filters into the context (obviously only logical for a subset):Point being, it would give a huge amount of flexibility and expressibility when writing Jinja.
Are you interested in contributing this feature?
Can do
Anything else?
I believe should be minimal code with just
core/dbt/context/base.py
needing to be edited:for adding
itertools
to themodules
var andfor adding
zip
.The text was updated successfully, but these errors were encountered: