-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Przemek Denkiewicz
committed
Aug 11, 2022
1 parent
a7b468b
commit 38ed99d
Showing
7 changed files
with
314 additions
and
6 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,3 +1,8 @@ | ||
{% materialization view, adapter='trino' -%} | ||
{{ return(create_or_replace_view()) }} | ||
{% set to_return = create_or_replace_view() %} | ||
{% set target_relation = this.incorporate(type='view') %} | ||
|
||
{% do persist_docs(target_relation, model) %} | ||
|
||
{% do return(to_return) %} | ||
{%- endmaterialization %} |
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,105 @@ | ||
seed_csv = """ | ||
id,name,some_date | ||
1,Easton,1981-05-20 06:46:51 | ||
2,Lillian,1978-09-03 18:10:33 | ||
3,Jeremiah,1982-03-11 03:59:51 | ||
4,Nolan,1976-05-06 20:21:35 | ||
""".lstrip() | ||
|
||
table_model = """ | ||
{{config(materialized = "table")}} | ||
select * from {{ ref('seed') }} | ||
""" | ||
|
||
view_model = """ | ||
{{config(materialized = "view")}} | ||
select * from {{ ref('seed') }} | ||
""" | ||
|
||
incremental_model = """ | ||
{{config(materialized = "incremental")}} | ||
select * from {{ ref('seed') }} | ||
""" | ||
|
||
table_profile_yml = """ | ||
version: 2 | ||
models: | ||
- name: table_model | ||
description: | | ||
Table model description "with double quotes" | ||
and with 'single quotes' as welll as other; | ||
'''abc123''' | ||
reserved -- characters | ||
-- | ||
/* comment */ | ||
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting | ||
columns: | ||
- name: id | ||
description: | | ||
id Column description "with double quotes" | ||
and with 'single quotes' as welll as other; | ||
'''abc123''' | ||
reserved -- characters | ||
-- | ||
/* comment */ | ||
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting | ||
tests: | ||
- unique | ||
- not_null | ||
- name: name | ||
description: | | ||
Fancy column description | ||
""" | ||
|
||
|
||
view_profile_yml = """ | ||
version: 2 | ||
models: | ||
- name: view_model | ||
description: | | ||
Table model description "with double quotes" | ||
and with 'single quotes' as welll as other; | ||
'''abc123''' | ||
reserved -- characters | ||
-- | ||
/* comment */ | ||
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting | ||
columns: | ||
- name: id | ||
tests: | ||
- unique | ||
- not_null | ||
- name: name | ||
tests: | ||
- not_null | ||
""" | ||
|
||
incremental_profile_yml = """ | ||
version: 2 | ||
models: | ||
- name: incremental_model | ||
description: | | ||
Table model description "with double quotes" | ||
and with 'single quotes' as welll as other; | ||
'''abc123''' | ||
reserved -- characters | ||
-- | ||
/* comment */ | ||
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting | ||
columns: | ||
- name: id | ||
description: | | ||
id Column description "with double quotes" | ||
and with 'single quotes' as welll as other; | ||
'''abc123''' | ||
reserved -- characters | ||
-- | ||
/* comment */ | ||
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting | ||
tests: | ||
- unique | ||
- not_null | ||
- name: name | ||
tests: | ||
- not_null | ||
""" |
177 changes: 177 additions & 0 deletions
177
tests/functional/adapter/persist_docs/test_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,177 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt, check_relations_equal, run_sql_with_adapter | ||
|
||
from tests.functional.adapter.persist_docs.fixtures import ( | ||
seed_csv, | ||
table_model, | ||
view_model, | ||
incremental_model, | ||
table_profile_yml, | ||
view_profile_yml, | ||
incremental_profile_yml | ||
) | ||
|
||
|
||
@pytest.mark.iceberg | ||
class TestPersistDocsBase: | ||
""" | ||
Testing persist_docs functionality | ||
""" | ||
|
||
@property | ||
def schema(self): | ||
return "default" | ||
|
||
# everything that goes in the "seeds" directory | ||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"seed.csv": seed_csv, | ||
} | ||
|
||
|
||
class TestPersistDocsTable(TestPersistDocsBase): | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"name": "persist_docs_tests", | ||
"models": { | ||
"+persist_docs": { | ||
"relation": True, | ||
"columns": True | ||
} | ||
}, | ||
"seeds": { | ||
"+column_types": { | ||
"some_date": "timestamp(6)" | ||
} | ||
} | ||
} | ||
|
||
# everything that goes in the "models" directory | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"table_model.sql": table_model, | ||
"table_persist_docs.yml": table_profile_yml, | ||
} | ||
|
||
def test_run_seed_test(self, project): | ||
# seed seeds | ||
results = run_dbt(["seed"], expect_pass=True) | ||
assert len(results) == 1 | ||
results = run_dbt(["run"], expect_pass=True) | ||
assert len(results) == 1 | ||
# test tests | ||
results = run_dbt(["test"], expect_pass=True) | ||
assert len(results) == 3 | ||
|
||
|
||
# Comments on views are not supported in Trino engine | ||
# https://github.com/trinodb/trino/issues/10705 | ||
class TestPersistDocsView(TestPersistDocsBase): | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"name": "persist_docs_tests", | ||
"models": { | ||
"+persist_docs": { | ||
"relation": True | ||
} | ||
}, | ||
"seeds": { | ||
"+column_types": { | ||
"some_date": "timestamp(6)" | ||
} | ||
} | ||
} | ||
|
||
# everything that goes in the "models" directory | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"view_model.sql": view_model, | ||
"view_persist_docs.yml": view_profile_yml, | ||
} | ||
|
||
def test_run_seed_test(self, project): | ||
# seed seeds | ||
results = run_dbt(["seed"], expect_pass=True) | ||
assert len(results) == 1 | ||
results = run_dbt(["run"], expect_pass=True) | ||
assert len(results) == 1 | ||
# test tests | ||
results = run_dbt(["test"], expect_pass=True) | ||
assert len(results) == 3 | ||
|
||
|
||
class TestPersistDocsIncremental(TestPersistDocsBase): | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"name": "persist_docs_tests", | ||
"models": { | ||
"+persist_docs": { | ||
"relation": True, | ||
"columns": True | ||
} | ||
}, | ||
"seeds": { | ||
"+column_types": { | ||
"some_date": "timestamp(6)" | ||
} | ||
} | ||
} | ||
|
||
# everything that goes in the "models" directory | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"incremental_model.sql": incremental_model, | ||
"incremental_persist_docs.yml": incremental_profile_yml, | ||
} | ||
|
||
def test_run_seed_test(self, project): | ||
# seed seeds | ||
results = run_dbt(["seed"], expect_pass=True) | ||
assert len(results) == 1 | ||
results = run_dbt(["run"], expect_pass=True) | ||
assert len(results) == 1 | ||
# test tests | ||
results = run_dbt(["test"], expect_pass=True) | ||
assert len(results) == 3 | ||
|
||
|
||
|
||
|
||
# The actual sequence of dbt commands and assertions | ||
# pytest will take care of all "setup" + "teardown" | ||
# def test_run_seed_test(self, project): | ||
# # seed seeds | ||
# results = run_dbt(["seed"], expect_pass=True) | ||
# assert len(results) == 1 | ||
# results = run_dbt(["run"], expect_pass=True) | ||
# assert len(results) == 1 | ||
# # test tests | ||
# results = run_dbt(["test"], expect_pass=True) | ||
# assert len(results) == 3 | ||
|
||
# check if the data was loaded correctly | ||
# check_relations_equal(project.adapter, ["seed", "table_model"]) | ||
|
||
# for table in ["table_model", "view_model", "incremental_model"]: | ||
# results = run_sql_with_adapter( | ||
# "describe memory.default.{table}".format(table=table), | ||
# fetch="all", | ||
# ) | ||
# print(results) | ||
# for result in results: | ||
# if result[0] == "Comment": | ||
# assert result[1].startswith(f"test model description") | ||
# if result[0] == "id": | ||
# assert result[2].startswith("id Column description") | ||
# if result[0] == "name": | ||
# assert result[2].startswith("Some stuff here and then a call to") |
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