-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Pass parsed_node
into generate_schema_name
.
#1463
Comments
+1 |
@nydnarb thanks for making this issue! The core challenge with operating in this part of dbt's codebase is that the state of the resources that dbt operates on are still in flux! The schema name for a model is determined during parsing, so there are still some attributes of the ParsedNode that haven't been finalized yet. Check out the _update_parsed_node_info function. The following attributes of the ParsedNode are all finalized in this order:
Looking at this code again, I think we're actually not doing the strictly correct thing when generating an alias name! Specifically, the
Only configs that are specified in I think there's a quick fix though - we just need to wait until these other attributes are finalized before calling Apologies for leading you astray in your Overall though, I love the suggestion presented here, and think it will be a great addition to dbt if we can get the specifics right.
Yep, totally agree! I didn't realize cc @beckjake - did I miss anything here? |
Feature description
Recently, I submitted a feature to allow dbt users to specify a
generate_alias_name
macro in their project. Therefore, for example, the name of the table that the model is being built in could be implemented as a function of context like thetarget
of the build ortags
on the model. When implementing that feature, we decided to pass anode
object into theget_alias
function. https://github.com/fishtown-analytics/dbt/blob/4b7bddb48189c926e2fc6b753bd5328ce4f953bc/core/dbt/parser/base.py#L213We have a use case where we would like to use different
schema
depending ontags
that might be included in a model (e.g., we might launch a model in production with aexperimental
tag). While investigating if I could update ourgenerate_schema_name
macro to access the model'stags
, I realized that there is nomodel
ornode
object in the available context.My proposal is that we make some kind of node or model object available at time of rendering a model's custom schema. I think it will be as easy as updating
get_schema
to also acceptparsed_node
: https://github.com/fishtown-analytics/dbt/blob/4b7bddb48189c926e2fc6b753bd5328ce4f953bc/core/dbt/parser/base.py#L209(Note, we would probably have to add it as a second input and not the first. If that's the case, we should reverse the order of the inputs in
get_alias
prior to release of custom aliases, for consistency).Who will this benefit?
My organization! But also, anyone who might want to dynamically generate schema names based on things in the model
config
, like tags, sortkeys, distkeys, materialization, etc. Not just, for example, thetarget
andschema
inconfig
.The text was updated successfully, but these errors were encountered: