Skip to content

Commit

Permalink
Refactor to use new batch context varaibles (#967)
Browse files Browse the repository at this point in the history
* 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.

* Add changie doc
  • Loading branch information
QMalcolm authored Dec 12, 2024
1 parent a145bc1 commit 0376909
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20241211-145132.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 0376909

Please sign in to comment.