Skip to content

Commit

Permalink
tests/integration/adapter/incremental/test_incremental.py: covered in…
Browse files Browse the repository at this point in the history
…sert+replace with tests
  • Loading branch information
bryzgaloff committed Jul 15, 2024
1 parent 6869ed2 commit e4bd2cc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/integration/adapter/incremental/test_base_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]

0 comments on commit e4bd2cc

Please sign in to comment.