diff --git a/.changes/unreleased/Features-20241218-153349.yaml b/.changes/unreleased/Features-20241218-153349.yaml new file mode 100644 index 00000000..fe7cf5d7 --- /dev/null +++ b/.changes/unreleased/Features-20241218-153349.yaml @@ -0,0 +1,7 @@ +kind: Features +body: Enable setting current value of dbt_valid_to +time: 2024-12-18T15:33:49.520897+01:00 +custom: + Author: damian3031 + Issue: "" + PR: "462" diff --git a/dbt/include/trino/macros/materializations/snapshot.sql b/dbt/include/trino/macros/materializations/snapshot.sql index c57e867b..433ce6ce 100644 --- a/dbt/include/trino/macros/materializations/snapshot.sql +++ b/dbt/include/trino/macros/materializations/snapshot.sql @@ -29,7 +29,12 @@ on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }} when matched - and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null + {% if config.get("dbt_valid_to_current") %} + and (DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} = {{ config.get('dbt_valid_to_current') }} or + DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null) + {% else %} + and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null + {% endif %} and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete') then update set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }}