diff --git a/CHANGELOG.md b/CHANGELOG.md index f99b14c76..f7164641c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## dbt-spark 1.2.0rc1 (Release TBD) + +- Incremental materialization updated to not drop table first if full refresh for delta lake format, as it already runs _create or replace table_ ([#286](https://github.com/dbt-labs/dbt-spark/issues/286), [#287](https://github.com/dbt-labs/dbt-spark/pull/287/)) + +### Contributors +- [@grindheim](https://github.com/grindheim) ([#287](https://github.com/dbt-labs/dbt-spark/pull/287/)) + ## dbt-spark 1.2.0b1 (June 24, 2022) ### Fixes diff --git a/dbt/include/spark/macros/materializations/incremental/incremental.sql b/dbt/include/spark/macros/materializations/incremental/incremental.sql index 8d8e69d93..99cd31db1 100644 --- a/dbt/include/spark/macros/materializations/incremental/incremental.sql +++ b/dbt/include/spark/macros/materializations/incremental/incremental.sql @@ -26,10 +26,14 @@ {{ run_hooks(pre_hooks) }} + {% set is_delta = (file_format == 'delta' and existing_relation.is_delta) %} + {% if existing_relation is none %} {% set build_sql = create_table_as(False, target_relation, sql) %} {% elif existing_relation.is_view or full_refresh_mode %} - {% do adapter.drop_relation(existing_relation) %} + {% if not is_delta %} {#-- If Delta, we will `create or replace` below, so no need to drop --#} + {% do adapter.drop_relation(existing_relation) %} + {% endif %} {% set build_sql = create_table_as(False, target_relation, sql) %} {% else %} {% do run_query(create_table_as(True, tmp_relation, sql)) %}