-
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
removed deprication for materialization-return and replaced it with a… #3893
Merged
+102
−49
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
30ff395
removed deprication for materialization-return and replaced it with a…
emmyoop 237048c
more explicit error check
emmyoop 080d273
removed deprication for materialization-return and replaced it with a…
emmyoop 5ce2900
more explicit error check
emmyoop 5871915
Merge branch '2798_enact_deprecations' of https://github.com/dbt-labs…
emmyoop f99cf12
fixed conflict
emmyoop f80825d
updated changelog
emmyoop 1810202
Pull in changes for the `0.21.0rc1` release (#3935)
092e96c
Merge branch 'develop' into 2798_enact_deprecations
emmyoop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/integration/053_custom_materialization/override-view-return-no-relation/dbt_project.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: view_adapter_override | ||
version: 2 | ||
macro-paths: ['macros'] | ||
config-version: 2 |
66 changes: 66 additions & 0 deletions
66
...tion/053_custom_materialization/override-view-return-no-relation/macros/override_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{# copy+pasting the default view impl #} | ||
{% materialization view, default %} | ||
|
||
{%- set identifier = model['alias'] -%} | ||
{%- set tmp_identifier = model['name'] + '__dbt_tmp' -%} | ||
{%- set backup_identifier = model['name'] + '__dbt_backup' -%} | ||
|
||
{%- set old_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) -%} | ||
{%- set target_relation = api.Relation.create(identifier=identifier, schema=schema, database=database, | ||
type='view') -%} | ||
{%- set intermediate_relation = api.Relation.create(identifier=tmp_identifier, | ||
schema=schema, database=database, type='view') -%} | ||
|
||
/* | ||
This relation (probably) doesn't exist yet. If it does exist, it's a leftover from | ||
a previous run, and we're going to try to drop it immediately. At the end of this | ||
materialization, we're going to rename the "old_relation" to this identifier, | ||
and then we're going to drop it. In order to make sure we run the correct one of: | ||
- drop view ... | ||
- drop table ... | ||
|
||
We need to set the type of this relation to be the type of the old_relation, if it exists, | ||
or else "view" as a sane default if it does not. Note that if the old_relation does not | ||
exist, then there is nothing to move out of the way and subsequentally drop. In that case, | ||
this relation will be effectively unused. | ||
*/ | ||
{%- set backup_relation_type = 'view' if old_relation is none else old_relation.type -%} | ||
{%- set backup_relation = api.Relation.create(identifier=backup_identifier, | ||
schema=schema, database=database, | ||
type=backup_relation_type) -%} | ||
|
||
{%- set exists_as_view = (old_relation is not none and old_relation.is_view) -%} | ||
|
||
{{ run_hooks(pre_hooks, inside_transaction=False) }} | ||
|
||
-- drop the temp relations if they exists for some reason | ||
{{ adapter.drop_relation(intermediate_relation) }} | ||
{{ adapter.drop_relation(backup_relation) }} | ||
|
||
-- `BEGIN` happens here: | ||
{{ run_hooks(pre_hooks, inside_transaction=True) }} | ||
|
||
-- build model | ||
{% call statement('main') -%} | ||
{{ create_view_as(intermediate_relation, sql) }} | ||
{%- endcall %} | ||
|
||
-- cleanup | ||
-- move the existing view out of the way | ||
{% if old_relation is not none %} | ||
{{ adapter.rename_relation(target_relation, backup_relation) }} | ||
{% endif %} | ||
{{ adapter.rename_relation(intermediate_relation, target_relation) }} | ||
|
||
{{ run_hooks(post_hooks, inside_transaction=True) }} | ||
|
||
{{ adapter.commit() }} | ||
|
||
{{ drop_relation_if_exists(backup_relation) }} | ||
|
||
{{ run_hooks(post_hooks, inside_transaction=False) }} | ||
|
||
{# do not return anything! #} | ||
{# {{ return({'relations': [target_relation]}) }} #} | ||
|
||
{%- endmaterialization -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎉