From d741c76e23b626bc7b0ab3373c43f7a2c51ad0c5 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 2 Dec 2024 11:05:29 -0500 Subject: [PATCH] Use timestamp_tz type in microbatch `delete` DDL (#1257) (cherry picked from commit 5cc5d224f9cc45802b8141472a594c2cdf0facb1) --- .changes/unreleased/Fixes-20241127-162204.yaml | 6 ++++++ .../snowflake/macros/materializations/merge.sql | 4 ++-- .../adapter/test_incremental_microbatch.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20241127-162204.yaml diff --git a/.changes/unreleased/Fixes-20241127-162204.yaml b/.changes/unreleased/Fixes-20241127-162204.yaml new file mode 100644 index 000000000..2b990b1f9 --- /dev/null +++ b/.changes/unreleased/Fixes-20241127-162204.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Use timestamp_tz type in microbatch `delete` DDL +time: 2024-11-27T16:22:04.103212-05:00 +custom: + Author: michelleark + Issue: "1256" diff --git a/dbt/include/snowflake/macros/materializations/merge.sql b/dbt/include/snowflake/macros/materializations/merge.sql index c8ac8d6fd..716a325c1 100644 --- a/dbt/include/snowflake/macros/materializations/merge.sql +++ b/dbt/include/snowflake/macros/materializations/merge.sql @@ -58,10 +58,10 @@ {#-- Add additional incremental_predicates to filter for batch --#} {% if model.config.get("__dbt_internal_microbatch_event_time_start") -%} - {% do incremental_predicates.append("DBT_INTERNAL_TARGET." ~ model.config.event_time ~ " >= TIMESTAMP '" ~ model.config.__dbt_internal_microbatch_event_time_start ~ "'") %} + {% do incremental_predicates.append("DBT_INTERNAL_TARGET." ~ model.config.event_time ~ " >= to_timestamp_tz('" ~ model.config.__dbt_internal_microbatch_event_time_start ~ "')") %} {% endif %} {% if model.config.__dbt_internal_microbatch_event_time_end -%} - {% do incremental_predicates.append("DBT_INTERNAL_TARGET." ~ model.config.event_time ~ " < TIMESTAMP '" ~ model.config.__dbt_internal_microbatch_event_time_end ~ "'") %} + {% do incremental_predicates.append("DBT_INTERNAL_TARGET." ~ model.config.event_time ~ " < to_timestamp_tz('" ~ model.config.__dbt_internal_microbatch_event_time_end ~ "')") %} {% endif %} {% do arg_dict.update({'incremental_predicates': incremental_predicates}) %} diff --git a/tests/functional/adapter/test_incremental_microbatch.py b/tests/functional/adapter/test_incremental_microbatch.py index f228c370c..f087596e1 100644 --- a/tests/functional/adapter/test_incremental_microbatch.py +++ b/tests/functional/adapter/test_incremental_microbatch.py @@ -3,6 +3,16 @@ BaseMicrobatch, ) +# Create input with UTC timestamps +_input_model_sql = """ +{{ config(materialized='table', event_time='event_time') }} +select 1 as id, to_timestamp_tz('2020-01-01 00:00:00-0') as event_time +union all +select 2 as id, to_timestamp_tz('2020-01-02 00:00:00-0') as event_time +union all +select 3 as id, to_timestamp_tz('2020-01-03 00:00:00-0') as event_time +""" + # No requirement for a unique_id for snowflake microbatch! _microbatch_model_no_unique_id_sql = """ @@ -16,6 +26,10 @@ class TestSnowflakeMicrobatch(BaseMicrobatch): def microbatch_model_sql(self) -> str: return _microbatch_model_no_unique_id_sql + @pytest.fixture(scope="class") + def input_model_sql(self) -> str: + return _input_model_sql + @pytest.fixture(scope="class") def insert_two_rows_sql(self, project) -> str: test_schema_relation = project.adapter.Relation.create(