From 188720860f09ce1850ccd956d80346086cdbf4ba Mon Sep 17 00:00:00 2001 From: Mila Page Date: Wed, 28 Aug 2024 23:29:31 -0700 Subject: [PATCH] Transient needs sophisticated handling based on what user specifies for transient manually. --- dbt/include/snowflake/macros/adapters.sql | 4 +++- .../macros/relations/table/create.sql | 23 +++++++++++-------- .../list_relations_tests/test_show_objects.py | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dbt/include/snowflake/macros/adapters.sql b/dbt/include/snowflake/macros/adapters.sql index d9d9d8753..1662b46a2 100644 --- a/dbt/include/snowflake/macros/adapters.sql +++ b/dbt/include/snowflake/macros/adapters.sql @@ -321,7 +321,9 @@ {% macro snowflake__show_iceberg_relations(schema_relation) %} - {%- set sql = 'show iceberg tables in ' ~ schema_relation ~ ';' %} + {%- set sql -%} + show iceberg tables in {{ schema_relation }} + {%- endset -%} {%- set result = run_query(sql) -%} {%- do return(result) -%} {% endmacro %} diff --git a/dbt/include/snowflake/macros/relations/table/create.sql b/dbt/include/snowflake/macros/relations/table/create.sql index 12ee13523..03107c7a1 100644 --- a/dbt/include/snowflake/macros/relations/table/create.sql +++ b/dbt/include/snowflake/macros/relations/table/create.sql @@ -84,22 +84,27 @@ {%- set is_iceberg = _is_iceberg_relation() -%} {%- set is_temporary = temporary -%} - {%- 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) }} - {%- endif %} + {%- if is_iceberg -%} + {# -- Check if user supplied a transient model config of True. #} + {%- if config.get('transient') == True -%} + {{ 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) }} + {%- endif %} - {%- if is_temporary and is_iceberg -%} - {{ exceptions.warn("Iceberg format relations cannot be temporary. Please remove either the transient or iceberg parameters from %s. If left unmodified, dbt will ignore 'transient'." % this) }} - {%- endif %} + {# -- Check if runtime is trying to create a Temporary Iceberg table. #} + {%- if is_temporary -%} + {{ exceptions.raise_compiler_error("Iceberg format relations cannot be temporary. Temporary is being inserted into an Iceberg format table while materializing %s." % this) }} + {%- endif %} - {%- if is_iceberg -%} {{ return('iceberg') }} + {%- elif is_temporary -%} {{ return('temporary') }} - {%- elif is_transient -%} + + {# -- Always supply transient on table create DDL unless user specifically sets transient to false. #} + {%- elif config.get('transient', default=true) -%} {{ return('transient') }} + {%- else -%} {{ return('') }} {%- endif -%} diff --git a/tests/functional/adapter/list_relations_tests/test_show_objects.py b/tests/functional/adapter/list_relations_tests/test_show_objects.py index e5eee39d9..f59dc335b 100644 --- a/tests/functional/adapter/list_relations_tests/test_show_objects.py +++ b/tests/functional/adapter/list_relations_tests/test_show_objects.py @@ -73,7 +73,7 @@ def list_relations_without_caching(project) -> List[SnowflakeRelation]: database=project.database, schema=project.test_schema, identifier="" ) with get_connection(my_adapter): - relations = my_adapter.list_relations_without_caching(schema) + relations = my_adapter.list_relations_without_caching(schema.path.schema) return relations def test_list_relations_without_caching(self, project):