-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/incremental predicates (#161)
### Description Updates the incremental materialization to include user supplied `incremental_predicates` and passes that to the `dbt_spark_get_incremental_sql` macro. The changes to `dbt_spark_get_incremental_sql` are updated in [dbt-spark PR #436](dbt-labs/dbt-spark#436) Co-authored-by: Takuya UESHIN <ueshin@databricks.com>
- Loading branch information
1 parent
1d85eb5
commit 8124c35
Showing
3 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
from dbt.tests.adapter.incremental.test_incremental_predicates import BaseIncrementalPredicates | ||
|
||
|
||
models__databricks_incremental_predicates_sql = """ | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = 'id' | ||
) }} | ||
{% if not is_incremental() %} | ||
select cast(1 as bigint) as id, 'hello' as msg, 'blue' as color | ||
union all | ||
select cast(2 as bigint) as id, 'goodbye' as msg, 'red' as color | ||
{% else %} | ||
-- merge will not happen on the above record where id = 2, so new record will fall to insert | ||
select cast(1 as bigint) as id, 'hey' as msg, 'blue' as color | ||
union all | ||
select cast(2 as bigint) as id, 'yo' as msg, 'green' as color | ||
union all | ||
select cast(3 as bigint) as id, 'anyway' as msg, 'purple' as color | ||
{% endif %} | ||
""" | ||
|
||
|
||
class TestIncrementalPredicatesMergeDatabricks(BaseIncrementalPredicates): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"models": {"+incremental_predicates": ["dbt_internal_dest.id != 2"]}} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"delete_insert_incremental_predicates.sql": ( | ||
models__databricks_incremental_predicates_sql | ||
) | ||
} | ||
|
||
|
||
class TestPredicatesMergeDatabricks(BaseIncrementalPredicates): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return {"models": {"+predicates": ["dbt_internal_dest.id != 2"]}} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"delete_insert_incremental_predicates.sql": ( | ||
models__databricks_incremental_predicates_sql | ||
) | ||
} |