-
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
ADAP-869: Support atomic replace in replace macro #8539
Conversation
This reverts commit 46e8aef.
This reverts commit d898469.
This reverts commit d755c51.
This reverts commit 03a15e7.
# Conflicts: # core/dbt/include/global_project/macros/relations/drop.sql # core/dbt/include/global_project/macros/relations/rename.sql # plugins/postgres/dbt/include/postgres/macros/relations/materialized_view/alter.sql
…relations` so that generics are close to the relation specific macros that they reference; also aligns with adapter macro files structure, to look more familiar
…r adapters that have a unique list of relation types, e.g. dbt-snowflake
…nd can be addressed properly at a later date
…default from drop_relation
Since postgres does not use replace in this way yet (it's not implemented for tables and views and materialized views don't support create or replace), it was tested against |
# Conflicts: # core/dbt/adapters/base/relation.py # core/dbt/include/global_project/macros/relations/materialized_view/_replace.sql # core/dbt/include/global_project/macros/relations/materialized_view/alter.sql # core/dbt/include/global_project/macros/relations/replace.sql
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
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.
Moved to relations/materialized_view/alter.sql
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.
Replaced with relations/materialized_view/replace.sql
, should have shown as a rename. That file was then updated to what shows below.
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.
Contents were moved to relations/view/replace.sql
.
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.
Replaced with relations/materialized_view/replace.sql
, should have shown as a rename. The contents of that file were then updated to the below.
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 was taken from the default create view statement in dbt-core
. Postgres did not overwrite it. It was then updated to run a create or replace
instead of just replace
and whitespace was adjusted for readability; otherwise it was left untouched.
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.
Contents of this file were moved to relations/materialized_view/alter.sql
.
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.
LGTM, but obviously needs Adapters 👍🏽 as well.
One nit on whether we can make the logic a bit more dynamic instead of having these large switch
statements everywhere.
resolves #
docs dbt-labs/docs.getdbt.com/#
Problem
The current replace macro does not support replacing an existing relation with a target relation of the same type using an atomic "create and replace". Instead it tries to do the stage/backup/swap method which uses at least two statements (one to drop the existing and one to create the target).
Solution
Update the replace macro to first check if the types are the same, and if so, if the type is a replaceable type. Some relation types are not replaceable (e.g. materialized views in Postgres). If this check fails, then head down the stage/backup/swap route.
Checklist