From e4bd2cc6bd6dd3dfab4f40d0f280aba9b200c424 Mon Sep 17 00:00:00 2001 From: Anton Bryzgalov Date: Fri, 17 Nov 2023 20:58:29 +0100 Subject: [PATCH] tests/integration/adapter/incremental/test_incremental.py: covered insert+replace with tests --- .../incremental/test_base_incremental.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/integration/adapter/incremental/test_base_incremental.py b/tests/integration/adapter/incremental/test_base_incremental.py index 24635db5..dc67aaff 100644 --- a/tests/integration/adapter/incremental/test_base_incremental.py +++ b/tests/integration/adapter/incremental/test_base_incremental.py @@ -181,3 +181,51 @@ def models(self): "incremental.sql": incremental_sql, "schema.yml": schema_base_yml, } + + +insert_replace_inc = """ +{{ config( + materialized='incremental', + incremental_strategy='insert+replace', + partition_by=['partitionKey1', 'partitionKey2'], + order_by=['orderKey'], + ) +}} +{% if not is_incremental() %} + SELECT partitionKey1, partitionKey2, orderKey, value + FROM VALUES( + 'partitionKey1 UInt8, partitionKey2 String, orderKey UInt8, value String', + (1, 'p1', 1, 'a'), (1, 'p1', 1, 'b'), (2, 'p1', 1, 'c'), (2, 'p2', 1, 'd') + ) +{% else %} + SELECT partitionKey1, partitionKey2, orderKey, value + FROM VALUES( + 'partitionKey1 UInt8, partitionKey2 String, orderKey UInt8, value String', + (1, 'p1', 2, 'e'), (3, 'p1', 2, 'f') + ) +{% endif %} +""" + + +class TestInsertReplaceIncremental: + @pytest.fixture(scope="class") + def models(self): + return {"insert_replace_inc.sql": insert_replace_inc} + + def test_insert_replace_incremental(self, project): + run_dbt() + result = project.run_sql("select * from insert_replace_inc order by partitionKey1, partitionKey2, orderKey", fetch="all") + assert result == [ + (1, 'p1', 1, 'a'), + (1, 'p1', 1, 'b'), + (2, 'p1', 1, 'c'), + (2, 'p2', 1, 'd'), + ] + run_dbt() + result = project.run_sql("select * from insert_replace_inc order by partitionKey1, partitionKey2, orderKey", fetch="all") + assert result == [ + (1, 'p1', 2, 'e'), + (2, 'p1', 1, 'c'), + (2, 'p2', 1, 'd'), + (3, 'p1', 2, 'f'), + ]