From b89629569ab343cdc6b02752a058948642e20d21 Mon Sep 17 00:00:00 2001 From: Damian Owsianny Date: Wed, 18 Dec 2024 15:20:04 +0100 Subject: [PATCH] Allow configuring of snapshot column names --- .changes/unreleased/Features-20241218-151645.yaml | 7 +++++++ dbt/include/trino/macros/materializations/snapshot.sql | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Features-20241218-151645.yaml 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'