Skip to content

Commit 6f2aae1

Browse files
VersusFacitmikealfarecolin-rogers-dbt
authored
Adap 1032/fix redshift incremental merge ddl (#1121)
Co-authored-by: Mike Alfare <[email protected]> Co-authored-by: Mike Alfare <[email protected]> Co-authored-by: Colin Rogers <[email protected]> Co-authored-by: Colin <[email protected]>
1 parent 0aad0df commit 6f2aae1

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: fix macro naming get_delete_insert_merge_sql
3+
time: 2025-06-05T14:54:21.254391-07:00
4+
custom:
5+
Author: VersusFacit
6+
Issue: "1032"

dbt-redshift/src/dbt/include/redshift/macros/materializations/incremental_delete_insert.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% macro default__get_delete_insert_merge_sql(target, source, unique_key, dest_columns, incremental_predicates) -%}
1+
{% macro redshift__get_delete_insert_merge_sql(target, source, unique_key, dest_columns, incremental_predicates) -%}
22
{%- set predicates = _update_predicates(target, incremental_predicates) -%}
33

44
{%- set dest_cols_csv = get_quoted_csv(dest_columns | map(attribute="name")) -%}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
import os
3+
4+
import pytest
5+
6+
from dbt.tests.util import run_dbt, run_dbt_and_capture
7+
8+
9+
MODEL_SQL = """
10+
{{ config(
11+
materialized='incremental',
12+
unique_key='id'
13+
) }}
14+
15+
SELECT 1 AS id, 'foo' AS value
16+
"""
17+
EXPECTED_SQL_FRAGMENTS = [
18+
"delete from",
19+
"using",
20+
"insert into",
21+
]
22+
UNEXPECTED_SQL_PATTERN = r"delete from\s+\{\{\s*this\s*\}\}\s+AS\s+\w+"
23+
24+
25+
@pytest.fixture(scope="class")
26+
def models():
27+
return {"model.sql": MODEL_SQL}
28+
29+
30+
def test_delete_insert_merge(project):
31+
"""
32+
Addresses https://github.com/dbt-labs/dbt-adapters/issues/1032
33+
"""
34+
# run once to create the base table
35+
run_dbt(["run"])
36+
37+
# run a second time to trigger the incremental load
38+
results, logs = run_dbt_and_capture(["--debug", "run"])
39+
40+
# make sure we did something
41+
assert len(results) == 1
42+
43+
# check the logs for expected values, or lack thereof
44+
for fragment in EXPECTED_SQL_FRAGMENTS:
45+
assert fragment in logs
46+
assert UNEXPECTED_SQL_PATTERN not in logs

0 commit comments

Comments
 (0)