-
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
Support for a generate_alias_name
macro.
#1350
Comments
Hey @nydnarb - thanks for opening this issue! I think that we're actually pretty well suited to implement something like this. I imagine
The default implementation would use the We had a pretty significant problem with the My only other thought is that we'll probably want to call this Is this something you'd be able to help out with implementing? I think the code block you pointed out is definitely the right place for this. We'd just need to implement a function like get_alias_func and provide a default macro implementation in the global project. |
I might be able to find some time to contribute. But I might have questions along the way. |
Cool! Let me know how I can be helpful -- happy to point you in the right direction as you get underway |
generate_table_name
macro.generate_alias_name
macro.
Fixed in #1363 |
Feature
Feature description
dbt
users can currently define agenerate_schema_name
macro. For example, we have a macroWhen the target is set to
multi_schema
, this macro ensures that theschema
defined in the model is used instead oftarget
's default schema. It would be amazing if we could also implement agenerate_table_name
macro. In many ways, agenerate_table_name
macro is a more flexible extension of thealias
concept that you introduced less than a year ago.I think this custom macro would be called here: https://github.com/fishtown-analytics/dbt/blob/f6402d3390f4baa7a6f76e546ed3565c79430c60/core/dbt/parser/base.py#L176
Who will this benefit?
Here is my use case. Suppose I have two users,
user1
anduser2
. Each has their own development schema,dbt_user1
anddbt_user2
. Now, I have a project that builds two tablesfoo.baz
andbar.baz
.foo.baz
comes from a SQL filefoo__baz.sql
withschema='foo'
andalias='baz'
. The other tablebar.baz
comes from a file calledbar__baz.sql
withschema='bar'
andalias='baz'
. In production, a superuser runs the job and everything is fine.However, when
user1
tries to run the job, they get an error becausedbt
wants to builddbt_user1.baz
twice. If I could write a customgenerate_table_name
macro, I might make it so that the tables are built as follows in development targets:dbt_user1.foo__baz
anddbt_user1.bar__baz
.Note, if the users had appropriate permissions to create schemata, this would not be a problem. For example, these tables would be built in
dbt_user1_foo.baz
anddbt_user1_bar.baz
, as perdbt
's documentation on custom schemas. However, we do not have that luxury right now. And I think agenerate_table_name
macro is, in many ways, the next evolution ofalias
.The text was updated successfully, but these errors were encountered: