From fbf09c9c910c8025bf791a76763d1759a4ef41ef Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 11 Dec 2024 14:25:46 -0600 Subject: [PATCH 1/2] Refactor to use new batch context varaibles During the betas/rcs of dbt-core 1.9.0, the varaibles `__dbt_internal_event_time_start` and `__dbt_internal_event_time_end` were available on the model in the jinja context. However when the final of dbt-core 1.9.0 was released, dbt-core started providing a `batch` object on the model available in the jinja context. This batch object made availble all the prevous information and more, and it is the "correct" way to get the information (i.e. `__dbt_internal_event_time_end` and `__dbt_internal_event_time_start` are deprecated. --- .../redshift/macros/materializations/incremental_merge.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt/include/redshift/macros/materializations/incremental_merge.sql b/dbt/include/redshift/macros/materializations/incremental_merge.sql index 8ddb8f96c..c9f8b98f6 100644 --- a/dbt/include/redshift/macros/materializations/incremental_merge.sql +++ b/dbt/include/redshift/macros/materializations/incremental_merge.sql @@ -89,13 +89,13 @@ {% do predicates.append(pred) %} {% endfor %} - {% if not model.config.get("__dbt_internal_microbatch_event_time_start") or not model.config.get("__dbt_internal_microbatch_event_time_end") -%} + {% if not model.batch or (not model.batch.event_time_start or not model.batch.event_time_end) -%} {% do exceptions.raise_compiler_error('dbt could not compute the start and end timestamps for the running batch') %} {% endif %} {#-- Add additional incremental_predicates to filter for batch --#} - {% do predicates.append(model.config.event_time ~ " >= TIMESTAMP '" ~ model.config.__dbt_internal_microbatch_event_time_start ~ "'") %} - {% do predicates.append(model.config.event_time ~ " < TIMESTAMP '" ~ model.config.__dbt_internal_microbatch_event_time_end ~ "'") %} + {% do predicates.append(model.config.event_time ~ " >= TIMESTAMP '" ~ model.batch.event_time_start ~ "'") %} + {% do predicates.append(model.config.event_time ~ " < TIMESTAMP '" ~ model.batch.event_time_end ~ "'") %} {% do arg_dict.update({'incremental_predicates': predicates}) %} delete from {{ target }} From 011918a8b92eee7aeb2ff6ef6fb256824cbbdee0 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 11 Dec 2024 14:51:43 -0600 Subject: [PATCH 2/2] Add changie doc --- .changes/unreleased/Under the Hood-20241211-145132.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20241211-145132.yaml diff --git a/.changes/unreleased/Under the Hood-20241211-145132.yaml b/.changes/unreleased/Under the Hood-20241211-145132.yaml new file mode 100644 index 000000000..561b03f83 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20241211-145132.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Refactor to use new batch context varaibles +time: 2024-12-11T14:51:32.239224-06:00 +custom: + Author: QMalcolm + Issue: "966"