From 312f7c31f565c2610cc57d87a27d74aca74e60cb Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Thu, 28 Mar 2024 14:53:38 -0400 Subject: [PATCH 1/3] iceberg as config --- dbt/include/snowflake/macros/materializations/table.sql | 2 +- dbt/include/snowflake/macros/relations/table/create.sql | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dbt/include/snowflake/macros/materializations/table.sql b/dbt/include/snowflake/macros/materializations/table.sql index ef201c705..c15336acc 100644 --- a/dbt/include/snowflake/macros/materializations/table.sql +++ b/dbt/include/snowflake/macros/materializations/table.sql @@ -16,7 +16,7 @@ {#-- 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 %} + {% if old_relation is not none %} {{ log("Dropping relation " ~ old_relation ~ " because it is of type " ~ old_relation.type) }} {{ drop_relation_if_exists(old_relation) }} {% endif %} diff --git a/dbt/include/snowflake/macros/relations/table/create.sql b/dbt/include/snowflake/macros/relations/table/create.sql index c6bc8f775..660dc8ff7 100644 --- a/dbt/include/snowflake/macros/relations/table/create.sql +++ b/dbt/include/snowflake/macros/relations/table/create.sql @@ -1,10 +1,14 @@ {% macro snowflake__create_table_as(temporary, relation, compiled_code, language='sql') -%} + {{ log('XXX: am i here?', info=True) }} {%- set transient = config.get('transient', default=true) -%} + {%- set iceberg = config.get('iceberg', default=true) -%} {% if temporary -%} {%- set table_type = "temporary" -%} - {%- elif transient -%} - {%- set table_type = "transient" -%} + {# {%- elif transient -%} + {%- set table_type = "transient" -%} #} + {%- elif iceberg -%} + {%- set table_type = "iceberg" -%} {%- else -%} {%- set table_type = "" -%} {%- endif %} From 20dca58abb762126a09b3cccb7aeb44952f5b965 Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Thu, 28 Mar 2024 16:36:07 -0400 Subject: [PATCH 2/3] explicit catalog and external volume --- dbt/include/snowflake/macros/relations/table/create.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dbt/include/snowflake/macros/relations/table/create.sql b/dbt/include/snowflake/macros/relations/table/create.sql index 660dc8ff7..6593081ba 100644 --- a/dbt/include/snowflake/macros/relations/table/create.sql +++ b/dbt/include/snowflake/macros/relations/table/create.sql @@ -2,6 +2,9 @@ {{ log('XXX: am i here?', info=True) }} {%- set transient = config.get('transient', default=true) -%} {%- set iceberg = config.get('iceberg', default=true) -%} + {%- set catalog = config.get('catalog') -%} + {%- set external_volume = config.get('external_volume') -%} + {% if temporary -%} {%- set table_type = "temporary" -%} @@ -37,6 +40,9 @@ {{ get_table_columns_and_constraints() }} {% set compiled_code = get_select_subquery(compiled_code) %} {% endif %} + {% if iceberg and catalog and external_volume %} + CATALOG="{{ catalog }}", EXTERNAL_VOLUME="{{ external_volume }}" + {% endif %} {% if copy_grants and not temporary -%} copy grants {%- endif %} as ( {%- if cluster_by_string is not none -%} From deb09467ebb402f9549a58110055c9516cc7897e Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Tue, 2 Apr 2024 16:40:24 -0400 Subject: [PATCH 3/3] add base location --- dbt/include/snowflake/macros/relations/table/create.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbt/include/snowflake/macros/relations/table/create.sql b/dbt/include/snowflake/macros/relations/table/create.sql index 6593081ba..42f60392c 100644 --- a/dbt/include/snowflake/macros/relations/table/create.sql +++ b/dbt/include/snowflake/macros/relations/table/create.sql @@ -4,7 +4,7 @@ {%- set iceberg = config.get('iceberg', default=true) -%} {%- set catalog = config.get('catalog') -%} {%- set external_volume = config.get('external_volume') -%} - + {%- set base_location = config.get('base_location') -%} {% if temporary -%} {%- set table_type = "temporary" -%} @@ -41,7 +41,9 @@ {% set compiled_code = get_select_subquery(compiled_code) %} {% endif %} {% if iceberg and catalog and external_volume %} - CATALOG="{{ catalog }}", EXTERNAL_VOLUME="{{ external_volume }}" + CATALOG="{{ catalog }}", + EXTERNAL_VOLUME="{{ external_volume }}", + BASE_LOCATION="{{ base_location }}" {% endif %} {% if copy_grants and not temporary -%} copy grants {%- endif %} as (