ScalefreeCOM / datavault4dbt

Scalefree's dbt package for a Data Vault 2.0 implementation congruent to the original Data Vault 2.0 definition by Dan Linstedt including the Staging Area, DV2.0 main entities, PITs and Snapshot Tables.
https://www.scalefree.com/
Apache License 2.0
134 stars 25 forks source link

Make Satellite HWM safe against outside truncate #74

Open tkirschke opened 1 year ago

tkirschke commented 1 year ago

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

for pointing out this issue and proposing a solution!

bschlottfeldt commented 8 months ago

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

github-actions[bot] commented 2 months ago

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

tkirschke commented 2 weeks ago

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