datavault4dbt icon indicating copy to clipboard operation
datavault4dbt copied to clipboard

Make Satellite HWM safe against outside truncate

Open tkirschke opened this issue 1 year ago • 3 comments

In All Kinds of Satellites there is a HWM logic applied for incremental runs. This logic checks

WHERE ldts > (SELECT max(ldts) FROM {{ this }})

But for cases, where this table is truncated outside of dbt, SELECT max(ldts) would return NULL, and on some databases the comparison ldts > NULL throws an error.

To avoid this, we need to insert the beginning-of-all-times for cases when max(ldts) returns NULL, like this:

WHERE ldts > (SELECT COALESCE(max(ldts), {{ datavault4dbt.beginning_of_all_times() }}) FROM {{ this }})

Thanks to

  • @dpolishchuk68
  • @underwatersven

for pointing out this issue and proposing a solution!

tkirschke avatar Jun 02 '23 08:06 tkirschke

COALESCE(MAX({{ src_ldts }}),{{ datavault4dbt.string_to_timestamp(timestamp_format, beginning_of_all_times) }})

bschlottfeldt avatar Jan 11 '24 17:01 bschlottfeldt

This issue is stale because it has been open for 90 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue. Otherwise it will be closed in 14 days

github-actions[bot] avatar Jul 08 '24 06:07 github-actions[bot]

check all macros and apply this to all that use a HWM

tkirschke avatar Sep 11 '24 12:09 tkirschke