-
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
Feature/alias #800
Feature/alias #800
Conversation
…er/dbt into feature/model-aliasing
…o model-aliasing $ git merge kickstarter/feature/model-aliasing CONFLICT (content): Merge conflict in dbt/utils.py CONFLICT (modify/delete): dbt/include/global_project/macros/materializations/table.sql deleted in HEAD and modified in kickstarter/feature/model-aliasing. Version kickstarter/feature/model-aliasing of dbt/include/global_project/macros/materializations/table.sql left in tree. CONFLICT (modify/delete): dbt/include/global_project/macros/materializations/bigquery.sql deleted in HEAD and modified in kickstarter/feature/model-aliasing. Version kickstarter/feature/model-aliasing of dbt/include/global_project/macros/materializations/bigquery.sql left in tree. 1. dbt/utils.py Some major changes are being introduced in 0.10.1: Implement relations api (#727) #727 5344f54#diff-196bbfafed32edaf1554550f65111f87 The Relation class was extracted into ... ./dbt/api/object.py class APIObject(dict) ./dbt/adapters/default/relation.py class DefaultRelation(APIObject) ./dbt/adapters/bigquery/relation.py class BigQueryRelation(DefaultRelation) ./dbt/adapters/snowflake/relation.py class SnowflakeRelation(DefaultRelation) Changing node.get('name') to node.get('alias') ... ./dbt/adapters/default/relation.py ./dbt/adapters/bigquery/relation.py ./dbt/adapters/snowflake/relation.py 2. dbt/include/global_project/macros/materializations/table.sql This was renamed to ... ./dbt/include/global_project/macros/materializations/table/table.sql 3. dbt/include/global_project/macros/materializations/bigquery.sql This was split into ... ./dbt/include/global_project/macros/materializations/table/bigquery_table.sql and ... ./dbt/include/global_project/macros/materializations/view/bigquery_view.sql 4. other instances of model['name'] The following file also mention model['name'] and probably need to change as well ... ./dbt/include/global_project/macros/materializations/archive/archive.sql ./dbt/include/global_project/macros/materializations/seed/bigquery.sql ./dbt/include/global_project/macros/materializations/seed/seed.sql Added comentary to ... ./dbt/exceptions.py 5. further changes Revert model.get('alias') to model.get('name') ... print_test_result_line in ./dbt/ui/printer.py (since in this context schema is NOT being used) Change model.get('name') to model.get('alias') ... print_seed_result_line in ./dbt/ui/printer.py (since in this context schema is also being used) Change node.get('name') to node.get('alias') ... _node_context in ./dbt/node_runners.py (since in this context schema is also being used) call_get_missing_columns in ./dbt/node_runners.py (since in this context schema is also being used) call_already_exists in ./dbt/node_runners.py (since in this context schema is also being used) 6. linting import lines must be under 80 characters https://www.python.org/dev/peps/pep-0328/
Wooooot! |
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.
if you get rid of that get_custom_alias
macro and just call node['alias']
directly, this is approved. i don't think overriding that macro in your project is going to work properly right now
rm -rf logs/ | ||
rm -rf target/ | ||
find . -type f -name '*.pyc' -delete | ||
find . -type d -name '__pycache__' -depth -delete |
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.
this looks really useful
{% set alias = config.get('alias', default_alias) %} | ||
{{ return(alias) }} | ||
|
||
{%- endmacro %} |
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.
does this actually work? looks like there are a lot of places (e.g. archive) where we use node['alias']
directly
long-run we should replace unrelated: your build is failing. |
@cmcarthur ok, I ripped out |
- add test for duped model names in different schemas
these tests are failing with a very upsetting:
This works locally for me, so I think it must be a postgres version thing. Just going to keep adding typecasts until it works /shrug |
|
||
{% macro bigquery__string_literal(s) %} | ||
cast('{{ s }}' as string) | ||
{% endmacro %} |
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.
random: let's move this macro https://github.com/fishtown-analytics/dbt-utils/blob/master/macros/cross_db_utils/safe_cast.sql from dbt-utils to dbt proper.
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, agree, that would be super useful. Do you think that should happen in this PR or a different one?
def project_config(self): | ||
return { | ||
"macro-paths": ['test/integration/026_aliases_test/macros'], | ||
} |
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 really like this as a test case for this feature
@drewbanin this looks great. i left a couple random thoughts here but you can ship this. |
Implement model aliasing Co-authored-by: Brian Abelson <[email protected]> Co-authored-by: Jonathan Kaczynski <[email protected]> automatic commit by git-black, original commits: 540631f
Reopened from #651, #771
Description (and original code courtesy of @abelsonlive). Thanks also to @jon-rtr for helping bring this branch up-to-date with development.
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....
Model aliasing is implemented for seed and model resources. An
alias
can be specified indbt_project.yml
or in a{{ config(alias=...) }}
block. Thename
attribute of a Relation object will reflect the alias, so{{ this.name }}
will return a model alias if one is present.