-
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.
Persist docs on incremental only if changed (#513)
- Loading branch information
Showing
8 changed files
with
215 additions
and
54 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
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,46 @@ | ||
merge_update_columns_sql = """ | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = 'id', | ||
merge_update_columns = ['msg'], | ||
) }} | ||
{% 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 %} | ||
-- msg will be updated, color will be ignored | ||
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 %} | ||
""" | ||
|
||
no_comment_schema = """ | ||
version: 2 | ||
models: | ||
- name: merge_update_columns_sql | ||
columns: | ||
- name: id | ||
- name: msg | ||
- name: color | ||
""" | ||
|
||
comment_schema = """ | ||
version: 2 | ||
models: | ||
- name: merge_update_columns_sql | ||
columns: | ||
- name: id | ||
description: This is the id column | ||
- name: msg | ||
description: This is the msg column | ||
- name: color | ||
""" |
34 changes: 34 additions & 0 deletions
34
tests/functional/adapter/incremental/test_incremental_persist_docs.py
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,34 @@ | ||
from dbt.tests import util | ||
from tests.functional.adapter.incremental import fixtures | ||
|
||
import pytest | ||
|
||
|
||
class TestIncrementalPersistDocs: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"merge_update_columns_sql.sql": fixtures.merge_update_columns_sql, | ||
"schema.yml": fixtures.no_comment_schema, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"test": { | ||
"+persist_docs": { | ||
"relation": True, | ||
"columns": True, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
def test_adding_comments(self, project): | ||
util.run_dbt(["run"]) | ||
util.write_file(fixtures.comment_schema, "models", "schema.yml") | ||
_, out = util.run_dbt_and_capture(["--debug", "run"]) | ||
assert "comment 'This is the id column'" in out | ||
assert "comment 'This is the msg column'" in out | ||
assert "comment ''" not in out |
Oops, something went wrong.