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" 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 }}