-
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
Model aliasing #651
Model aliasing #651
Conversation
Couple of things from my first pass:
This is so good! It functionally works flawlessly as far as I can tell. Going to stress test this some more over the weekend, but so far, so good :) |
dbt/context/common.py
Outdated
@@ -45,7 +45,7 @@ def __init__(self, model, adapter, profile): | |||
def wrap_with_profile_and_model_name(self, fn): | |||
def wrapped(*args, **kwargs): | |||
args = (self.profile,) + args | |||
kwargs['model_name'] = self.model.get('name') | |||
kwargs['model_name'] = self.model.get('alias') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to do this. The adapters use this model_name
arg to name their database connection in the pool. I think this line might make it possible for two different models to grab the same connection, which would probably be undesirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think this might be causing bugs on my branch...
dbt/context/common.py
Outdated
@@ -55,7 +55,7 @@ def type(self): | |||
|
|||
def commit(self): | |||
return self.adapter.commit_if_has_connection( | |||
self.profile, self.model.get('name')) | |||
self.profile, self.model.get('alias')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. This arg is used to find the connection in the default
adapter.
@@ -318,6 +322,8 @@ def is_blocking_dependency(node): | |||
def get_materialization(node): | |||
return node.get('config', {}).get('materialized') | |||
|
|||
def get_alias(node): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
RE: logging. I was able to fix the lines you mentioned, but i'm still seeing this output:
Where the |
@abelsonlive ah, yeah, good catch. The model name is injected in the describe_node function of these |
@abelsonlive are you blocked on anything here? I can help resolve the merge conflicts if you'd like |
@drewbanin yeah, it seems like even when I change |
@abelsonlive interesting... In that same |
dbt/utils.py
Outdated
@@ -39,11 +40,14 @@ def __init__(self, profile, adapter, node, use_temp=False): | |||
self.node = node | |||
self.schema = node.get('schema') | |||
self.name = node.get('name') | |||
# set alias, defaults to name | |||
self.alias = get_alias(node) | |||
self.node['alias'] = get_alias(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! Let's not mutate the node
here!
I think node['alias']
should be set over here instead. The schema
attribute is set on line 222 and 240 in that file. I think we'll want to do something similar here for alias
.
This should also fix the issue with the START
line log output I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing that line of code caused my initial tests to fail
Alright this should be good to go now! Finally got the proper log output. Good look on using |
@abelsonlive amazing! I think we should probably figure out how to get Let's try to get this PR in for the 0.9.3 release around a month or so from now. I can spend some time figuring out what's going wrong here right after we drop the 0.9.2 release :) Thanks for contributing!! |
WHAT
This P.R. implements model aliasing RE: #637.
WHY
To enable more control over how
dbt
materializes tables.HOW
This P.R. adds an
alias
parameter to the modelconfig
. If not present, this parameter will default to thename
of the model (AKA the parsed file path of the model). This implementation is preferable because it maintains the use of the filename inref
calls, thereby enablingdbt
users to have distinct model names, but non-distinct table names.The one nasty thing here is that now all materializations reference
model['alias']
when constructing table names (I suspect this might also break some stuff indbt-utils
). It may be preferable to add atable
key to a node so that these references are easier to read.