Skip to content

Commit

Permalink
Allow configuring of snapshot column names
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Dec 20, 2024
1 parent a235cf9 commit 570563e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20241218-151645.yaml
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 6 additions & 4 deletions dbt/include/trino/macros/materializations/snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 570563e

Please sign in to comment.