diff --git a/.changes/unreleased/Features-20241218-151645.yaml b/.changes/unreleased/Features-20241218-151645.yaml new file mode 100644 index 00000000..c1e0e5c8 --- /dev/null +++ b/.changes/unreleased/Features-20241218-151645.yaml @@ -0,0 +1,7 @@ +kind: Features +body: Allow configuring of snapshot column names +time: 2024-12-18T15:16:45.941759+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 de417bd7..c57e867b 100644 --- a/dbt/include/trino/macros/materializations/snapshot.sql +++ b/dbt/include/trino/macros/materializations/snapshot.sql @@ -22,15 +22,17 @@ {% macro trino__snapshot_merge_sql(target, source, insert_cols) -%} {%- set insert_cols_csv = insert_cols | join(', ') -%} - merge into {{ target }} as DBT_INTERNAL_DEST + {%- set columns = config.get("snapshot_table_column_names") or get_snapshot_table_column_names() -%} + + merge into {{ target.render() }} as DBT_INTERNAL_DEST using {{ source }} as DBT_INTERNAL_SOURCE - on DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id + on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }} when matched - and DBT_INTERNAL_DEST.dbt_valid_to is null + and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete') then update - set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to + set {{ columns.dbt_valid_to }} = DBT_INTERNAL_SOURCE.{{ columns.dbt_valid_to }} when not matched and DBT_INTERNAL_SOURCE.dbt_change_type = 'insert'