Skip to content

Commit

Permalink
Finish todo items and begin cleaning code.
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Aug 29, 2024
1 parent 5afb551 commit 53eb5b9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/snowflake/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def is_dynamic_table(self) -> bool:

@property
def is_iceberg_format(self) -> bool:
return self.object_format == SnowflakeRelationType.ICEBERG
return self.object_format == SnowflakeObjectFormat.ICEBERG

@classproperty
def DynamicTable(cls) -> str:
Expand Down
3 changes: 3 additions & 0 deletions dbt/adapters/snowflake/relation_configs/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
class SnowflakeObjectFormat(StrEnum):
DEFAULT = "default"
ICEBERG = "iceberg"

def __str__(self):
return self.value
36 changes: 30 additions & 6 deletions dbt/include/snowflake/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

{{ run_hooks(pre_hooks) }}

{#-- Drop the relation if it was a view to "convert" it in a table. This may lead to
-- downtime, but it should be a relatively infrequent occurrence #}
{% if old_relation is not none and not old_relation.is_table %}
{{ log("Dropping relation " ~ old_relation ~ " because it is of type " ~ old_relation.type) }}
{{ drop_relation_if_exists(old_relation) }}
{% endif %}
{{ drop_old_relation_as_needed(old_relation, target_relation) }}

{% call statement('main', language=language) -%}
{{ create_table_as(False, target_relation, compiled_code, language) }}
Expand Down Expand Up @@ -85,3 +80,32 @@ def main(session):
# dbt = dbtObj(session.table)
# df = model(dbt, session)
{%endmacro%}


{% macro drop_old_relation_as_needed(old_relation, target_relation) %}
{#
-- Each of these will cause some latency, but it shoudl be a relatively infrequent occurrence.

-- An existing view must be dropped for model to "converT" into a table"
#}
{% if old_relation is not none and not old_relation.is_table %}
{{ log("Dropping relation " ~ old_relation ~ " because it is of type " ~ old_relation.type) }}
{{ drop_relation_if_exists(old_relation) }}
{% endif %}

{#
-- An existing Iceberg table must be dropped for model to "convert" into a table.
#}
{% if old_relation is not none and old_relation.is_iceberg_format %}
{{ log("Dropping relation " ~ old_relation ~ " because it is an Iceberg format table " ~ old_relation.object_format) }}
{{ drop_relation_if_exists(old_relation) }}
{% endif %}

{#
-- An existing table must be dropped for model to "convert" into an Iceberg table.
#}
{% if old_relation is not none and old_relation.is_table and target_relation.is_iceberg_format %}
{{ log("Dropping relation " ~ old_relation ~ " because it is a table and target relation is Iceberg format") }}
{{ drop_relation_if_exists(old_relation) }}
{% endif %}
{% endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/snowflake/macros/relations/table/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

{%- set is_iceberg = _is_iceberg_relation() -%}
{%- set is_temporary = temporary -%}
{%- set is_transient = config.get('transient', default=true) -%}
{%- set is_transient = config.get('transient', default=False) -%}

{%- if is_transient and is_iceberg -%}
{{ exceptions.warn("Iceberg format relations cannot be transient. Please remove either the transient or iceberg parameters from %s. If left unmodified, dbt will ignore 'transient'." % this) }}
Expand Down

0 comments on commit 53eb5b9

Please sign in to comment.