-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADAP-821: Add support for replacing dynamic tables with tables/views …
…and vice versa (#753) * restructure macros directory, create separate files and directories for each ddl statement and relation type * pull create_or_replace_view into dbt-snowflake, update conditional to drop all non-views versus drop all tables * removed unnecessary create abstractions to simplify diffs * implement create or replace * test against clone replace branch * update renameable_relations and replaceable_relations to use frozensets for unmutable defaults --------- Co-authored-by: Matthew McKnight <[email protected]> Co-authored-by: colin-rogers-dbt <[email protected]>
- Loading branch information
1 parent
01f2c3e
commit eb4fd78
Showing
20 changed files
with
218 additions
and
132 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Support replacing tables/views with dynamic tables and vice versa | ||
time: 2023-08-22T23:47:32.27784-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "753" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% macro snowflake__get_create_sql(relation, sql) %} | ||
|
||
{% if relation.is_dynamic_table %} | ||
{{ snowflake__get_create_dynamic_table_as_sql(relation, sql) }} | ||
|
||
{% else %} | ||
{{ default__get_create_sql(relation, sql) }} | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{% macro snowflake__drop_relation(relation) -%} | ||
{%- if relation.is_dynamic_table -%} | ||
{% call statement('drop_relation', auto_begin=False) -%} | ||
drop dynamic table if exists {{ relation }} | ||
{%- endcall %} | ||
{%- else -%} | ||
{{- default__drop_relation(relation) -}} | ||
{%- endif -%} | ||
{% macro snowflake__get_drop_sql(relation) %} | ||
|
||
{% if relation.is_dynamic_table %} | ||
{{ snowflake__get_drop_dynamic_table_sql(relation) }} | ||
|
||
{% else %} | ||
{{ default__get_drop_sql(relation) }} | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} |
5 changes: 0 additions & 5 deletions
5
dbt/include/snowflake/macros/relations/dynamic_table/_replace.sql
This file was deleted.
Oops, something went wrong.
12 changes: 5 additions & 7 deletions
12
dbt/include/snowflake/macros/relations/dynamic_table/alter.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
3 changes: 1 addition & 2 deletions
3
dbt/include/snowflake/macros/relations/dynamic_table/create.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
12 changes: 12 additions & 0 deletions
12
dbt/include/snowflake/macros/relations/dynamic_table/replace.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,12 @@ | ||
{% macro snowflake__get_replace_dynamic_table_sql(relation, sql) %} | ||
|
||
create or replace dynamic table {{ relation }} | ||
target_lag = '{{ config.get("target_lag") }}' | ||
warehouse = {{ config.get("snowflake_warehouse") }} | ||
as ( | ||
{{ sql }} | ||
) | ||
; | ||
{{ snowflake__refresh_dynamic_table(relation) }} | ||
|
||
{% endmacro %} |
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,11 @@ | ||
{% macro snowflake__get_replace_sql(existing_relation, target_relation, sql) %} | ||
|
||
{% if existing_relation.is_dynamic_table and target_relation.is_dynamic_table %} | ||
{{ snowflake__get_replace_dynamic_table_sql(target_relation, sql) }} | ||
|
||
{% else %} | ||
{{ default__get_replace_sql(existing_relation, target_relation, sql) }} | ||
|
||
{% endif %} | ||
|
||
{% endmacro %} |
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,3 @@ | ||
{% macro snowflake__get_drop_table_sql(relation) %} | ||
drop table if exists {{ relation }} cascade | ||
{% endmacro %} |
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,3 @@ | ||
{%- macro snowflake__get_rename_table_sql(relation, new_name) -%} | ||
alter table {{ relation }} rename to {{ new_name }} | ||
{%- endmacro -%} |
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,3 @@ | ||
{% macro snowflake__get_replace_table_sql(relation, sql) %} | ||
{{ snowflake__create_table_as(False, relation, sql) }} | ||
{% endmacro %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro snowflake__get_drop_view_sql(relation) %} | ||
drop view if exists {{ relation }} cascade | ||
{% endmacro %} |
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,3 @@ | ||
{%- macro snowflake__get_rename_view_sql(relation, new_name) -%} | ||
alter view {{ relation }} rename to {{ new_name }} | ||
{%- endmacro -%} |
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,3 @@ | ||
{% macro snowflake__get_replace_view_sql(relation, sql) %} | ||
{{ snowflake__create_view_as(relation, sql) }} | ||
{% endmacro %} |
Oops, something went wrong.