Wrappable Relation
for custom rendering
#8560
github-christophe-oudar
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
Relation
is the powerful class that's used for multiple core functions asref
,source
orthis
jinja functions.Those functions can be overridden for a lot of custom behavior such as CI, sandboxing, staging or custom production environments.
One of the use cases that matters to me is CI and dev environments: in those environments, I want to LIMIT the input data for the model and I want to do so "automatically" so that developers don't have to think about it (and forget it).
Problem
Creating relations is possible through
api.Relation.create
function however as visible in the code:It doesn't provide a way to change the
render
method:Solution
To introduce a way to have that wrapping feature work, I'd suggest to have a new
Optional
value to a jinja function that takes the relation and expect a string output in theapi.Relation.create
function. That way we could then update the render method to execute the custom render if present or fallback on the usual one else.Usage
Then following
ref
snippet would work (assumingrender
onrel
is the original render):So that
mydatabase
.myschema
.mytable
is replaced in every query byAlternative considered
I think it exists some alternative such as inferring a new "intermediate" ephemeral model that would have the same behavior but I'm not sure it would fit the dbt architecture as I don't think we want to create model dynamically as discussed in #5101 but maybe it could be revisited?
Beta Was this translation helpful? Give feedback.
All reactions