-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from dbt-msft/incremental-tests
[incremental models] add tests, various bugfixes and support for incremental predicates
- Loading branch information
Showing
5 changed files
with
188 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,120 @@ | ||
import pytest | ||
from dbt.tests.adapter.incremental.fixtures import ( | ||
_MODELS__A, | ||
_MODELS__INCREMENTAL_APPEND_NEW_COLUMNS, | ||
_MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_REMOVE_ONE, | ||
_MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_REMOVE_ONE_TARGET, | ||
_MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_TARGET, | ||
_MODELS__INCREMENTAL_FAIL, | ||
_MODELS__INCREMENTAL_IGNORE_TARGET, | ||
_MODELS__INCREMENTAL_SYNC_ALL_COLUMNS, | ||
_MODELS__INCREMENTAL_SYNC_REMOVE_ONLY, | ||
) | ||
from dbt.tests.adapter.incremental.test_incremental_on_schema_change import ( | ||
BaseIncrementalOnSchemaChange, | ||
) | ||
from dbt.tests.adapter.incremental.test_incremental_predicates import BaseIncrementalPredicates | ||
from dbt.tests.adapter.incremental.test_incremental_unique_id import BaseIncrementalUniqueKey | ||
|
||
_MODELS__INCREMENTAL_IGNORE = """ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
unique_key='id', | ||
on_schema_change='ignore' | ||
) | ||
}} | ||
WITH source_data AS (SELECT * FROM {{ ref('model_a') }} ) | ||
{% if is_incremental() %} | ||
SELECT | ||
id, | ||
field1, | ||
field2, | ||
field3, | ||
field4 | ||
FROM source_data | ||
WHERE id NOT IN (SELECT id from {{ this }} ) | ||
{% else %} | ||
SELECT TOP 3 id, field1, field2 FROM source_data | ||
{% endif %} | ||
""" | ||
|
||
_MODELS__INCREMENTAL_SYNC_REMOVE_ONLY_TARGET = """ | ||
{{ | ||
config(materialized='table') | ||
}} | ||
with source_data as ( | ||
select * from {{ ref('model_a') }} | ||
) | ||
{% set string_type = dbt.type_string() %} | ||
select id | ||
,cast(field1 as {{string_type}}) as field1 | ||
from source_data | ||
""" | ||
|
||
_MODELS__INCREMENTAL_SYNC_ALL_COLUMNS_TARGET = """ | ||
{{ | ||
config(materialized='table') | ||
}} | ||
with source_data as ( | ||
select * from {{ ref('model_a') }} | ||
) | ||
{% set string_type = dbt.type_string() %} | ||
select id | ||
,cast(field1 as {{string_type}}) as field1 | ||
--,field2 | ||
,cast(case when id <= 3 then null else field3 end as {{string_type}}) as field3 | ||
,cast(case when id <= 3 then null else field4 end as {{string_type}}) as field4 | ||
from source_data | ||
""" | ||
|
||
|
||
class TestBaseIncrementalUniqueKeySQLServer(BaseIncrementalUniqueKey): | ||
pass | ||
|
||
|
||
class TestIncrementalOnSchemaChangeSQLServer(BaseIncrementalOnSchemaChange): | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"incremental_sync_remove_only.sql": _MODELS__INCREMENTAL_SYNC_REMOVE_ONLY, | ||
"incremental_ignore.sql": _MODELS__INCREMENTAL_IGNORE, | ||
"incremental_sync_remove_only_target.sql": _MODELS__INCREMENTAL_SYNC_REMOVE_ONLY_TARGET, # noqa: E501 | ||
"incremental_ignore_target.sql": _MODELS__INCREMENTAL_IGNORE_TARGET, | ||
"incremental_fail.sql": _MODELS__INCREMENTAL_FAIL, | ||
"incremental_sync_all_columns.sql": _MODELS__INCREMENTAL_SYNC_ALL_COLUMNS, | ||
"incremental_append_new_columns_remove_one.sql": _MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_REMOVE_ONE, # noqa: E501 | ||
"model_a.sql": _MODELS__A, | ||
"incremental_append_new_columns_target.sql": _MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_TARGET, # noqa: E501 | ||
"incremental_append_new_columns.sql": _MODELS__INCREMENTAL_APPEND_NEW_COLUMNS, | ||
"incremental_sync_all_columns_target.sql": _MODELS__INCREMENTAL_SYNC_ALL_COLUMNS_TARGET, # noqa: E501 | ||
"incremental_append_new_columns_remove_one_target.sql": _MODELS__INCREMENTAL_APPEND_NEW_COLUMNS_REMOVE_ONE_TARGET, # noqa: E501 | ||
} | ||
|
||
|
||
class TestIncrementalPredicatesDeleteInsertSQLServer(BaseIncrementalPredicates): | ||
pass | ||
|
||
|
||
class TestPredicatesDeleteInsertSQLServer(BaseIncrementalPredicates): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"models": {"+predicates": ["id != 2"], "+incremental_strategy": "delete+insert"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters