-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'fork/updateRelationConfig' into updateR…
…elationConfig
- Loading branch information
Showing
9 changed files
with
284 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# **what?** | ||
# Checks that a file has been committed under the /.changes directory | ||
# as a new CHANGELOG entry. Cannot check for a specific filename as | ||
# it is dynamically generated by change type and timestamp. | ||
# This workflow runs on pull_request_target because it requires | ||
# secrets to post comments. | ||
|
||
# **why?** | ||
# Ensure code change gets reflected in the CHANGELOG. | ||
|
||
# **when?** | ||
# This will run for all PRs going into main. It will | ||
# run when they are opened, reopened, when any label is added or removed | ||
# and when new code is pushed to the branch. The action will get | ||
# skipped if the 'Skip Changelog' label is present is any of the labels. | ||
|
||
name: Check Changelog Entry | ||
|
||
on: | ||
pull_request_target: | ||
types: [opened, reopened, labeled, unlabeled, synchronize] | ||
paths-ignore: ['.changes/**', '.github/**', 'tests/**', 'third-party-stubs/**', '**.md', '**.yml'] | ||
|
||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
changelog: | ||
uses: dbt-labs/actions/.github/workflows/changelog-existence.yml@main | ||
with: | ||
changelog_comment: 'Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see [the contributing guide](https://github.com/dbt-labs/dbt-adapters/blob/main/CONTRIBUTING.md#adding-changelog-entry).' | ||
skip_label: 'Skip Changelog' | ||
secrets: inherit |
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,3 @@ | ||
from pkgutil import extend_path | ||
|
||
__path__ = extend_path(__path__, __name__) | ||
__path__ = extend_path(__path__, __name__) |
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,7 @@ | ||
{% macro cast(field, type) %} | ||
{{ return(adapter.dispatch('cast', 'dbt') (field, type)) }} | ||
{% endmacro %} | ||
|
||
{% macro default__cast(field, type) %} | ||
cast({{field}} as {{type}}) | ||
{% endmacro %} |
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,49 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
|
||
|
||
my_model_sql = """ | ||
select | ||
tested_column from {{ ref('my_upstream_model')}} | ||
""" | ||
|
||
my_upstream_model_sql = """ | ||
select 1 as tested_column | ||
""" | ||
|
||
test_my_model_yml = """ | ||
unit_tests: | ||
- name: test_my_model | ||
model: my_model | ||
given: | ||
- input: ref('my_upstream_model') | ||
rows: | ||
- {tested_column: 1} | ||
- {TESTED_COLUMN: 2} | ||
- {tested_colUmn: 3} | ||
expect: | ||
rows: | ||
- {tested_column: 1} | ||
- {TESTED_COLUMN: 2} | ||
- {tested_colUmn: 3} | ||
""" | ||
|
||
|
||
class BaseUnitTestCaseInsensivity: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_model_sql, | ||
"my_upstream_model.sql": my_upstream_model_sql, | ||
"unit_tests.yml": test_my_model_yml, | ||
} | ||
|
||
def test_case_insensitivity(self, project): | ||
results = run_dbt(["run"]) | ||
assert len(results) == 2 | ||
|
||
results = run_dbt(["test"]) | ||
|
||
|
||
class TestPosgresUnitTestCaseInsensitivity(BaseUnitTestCaseInsensivity): | ||
pass |
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,62 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt, run_dbt_and_capture | ||
|
||
|
||
my_model_sql = """ | ||
select | ||
tested_column from {{ ref('my_upstream_model')}} | ||
""" | ||
|
||
my_upstream_model_sql = """ | ||
select 1 as tested_column | ||
""" | ||
|
||
test_my_model_yml = """ | ||
unit_tests: | ||
- name: test_invalid_input_column_name | ||
model: my_model | ||
given: | ||
- input: ref('my_upstream_model') | ||
rows: | ||
- {invalid_column_name: 1} | ||
expect: | ||
rows: | ||
- {tested_column: 1} | ||
- name: test_invalid_expect_column_name | ||
model: my_model | ||
given: | ||
- input: ref('my_upstream_model') | ||
rows: | ||
- {tested_column: 1} | ||
expect: | ||
rows: | ||
- {invalid_column_name: 1} | ||
""" | ||
|
||
|
||
class BaseUnitTestInvalidInput: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_model_sql, | ||
"my_upstream_model.sql": my_upstream_model_sql, | ||
"unit_tests.yml": test_my_model_yml, | ||
} | ||
|
||
def test_invalid_input(self, project): | ||
results = run_dbt(["run"]) | ||
assert len(results) == 2 | ||
|
||
_, out = run_dbt_and_capture( | ||
["test", "--select", "test_name:test_invalid_input_column_name"], expect_pass=False | ||
) | ||
assert "Invalid column name: 'invalid_column_name' in unit test fixture for 'my_upstream_model'." in out | ||
|
||
_, out = run_dbt_and_capture( | ||
["test", "--select", "test_name:test_invalid_expect_column_name"], expect_pass=False | ||
) | ||
assert "Invalid column name: 'invalid_column_name' in unit test fixture for expected output." in out | ||
|
||
|
||
class TestPostgresUnitTestInvalidInput(BaseUnitTestInvalidInput): | ||
pass |
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,84 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import write_file, run_dbt | ||
|
||
my_model_sql = """ | ||
select | ||
tested_column from {{ ref('my_upstream_model')}} | ||
""" | ||
|
||
my_upstream_model_sql = """ | ||
select | ||
{sql_value} as tested_column | ||
""" | ||
|
||
test_my_model_yml = """ | ||
unit_tests: | ||
- name: test_my_model | ||
model: my_model | ||
given: | ||
- input: ref('my_upstream_model') | ||
rows: | ||
- {{ tested_column: {yaml_value} }} | ||
expect: | ||
rows: | ||
- {{ tested_column: {yaml_value} }} | ||
""" | ||
|
||
|
||
class BaseUnitTestingTypes: | ||
@pytest.fixture | ||
def data_types(self): | ||
# sql_value, yaml_value | ||
return [ | ||
["1", "1"], | ||
["'1'", "1"], | ||
["true", "true"], | ||
["DATE '2020-01-02'", "2020-01-02"], | ||
["TIMESTAMP '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], | ||
["TIMESTAMPTZ '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], | ||
["'1'::numeric", "1"], | ||
[ | ||
"""'{"bar": "baz", "balance": 7.77, "active": false}'::json""", | ||
"""'{"bar": "baz", "balance": 7.77, "active": false}'""", | ||
], | ||
# TODO: support complex types | ||
# ["ARRAY['a','b','c']", """'{"a", "b", "c"}'"""], | ||
# ["ARRAY[1,2,3]", """'{1, 2, 3}'"""], | ||
] | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_model_sql, | ||
"my_upstream_model.sql": my_upstream_model_sql, | ||
"schema.yml": test_my_model_yml, | ||
} | ||
|
||
def test_unit_test_data_type(self, project, data_types): | ||
for sql_value, yaml_value in data_types: | ||
# Write parametrized type value to sql files | ||
write_file( | ||
my_upstream_model_sql.format(sql_value=sql_value), | ||
"models", | ||
"my_upstream_model.sql", | ||
) | ||
|
||
# Write parametrized type value to unit test yaml definition | ||
write_file( | ||
test_my_model_yml.format(yaml_value=yaml_value), | ||
"models", | ||
"schema.yml", | ||
) | ||
|
||
results = run_dbt(["run", "--select", "my_upstream_model"]) | ||
assert len(results) == 1 | ||
|
||
try: | ||
run_dbt(["test", "--select", "my_model"]) | ||
except Exception: | ||
raise AssertionError(f"unit test failed when testing model with {sql_value}") | ||
|
||
|
||
class TestPostgresUnitTestingTypes(BaseUnitTestingTypes): | ||
pass |