-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functional tests for unit testing #976
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e62b73d
setup CI
MichelleArk 688baa6
TestSparkUnitTestCaseInsensitivity, TestSparkUnitTestInvalidInput
MichelleArk 0b37836
TestSparkUnitTestingTypes - primative types
MichelleArk 24bc6c1
Merge branch 'main' into test-unit-testing
MichelleArk fa083cf
implement safe_cast + add tests for array, map, named_struct for unit…
MichelleArk f45280d
refactor safe_cast for readability, changelog entry
MichelleArk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 @@ | ||
kind: Features | ||
body: Implement spark__safe_cast and add functional tests for unit testing | ||
time: 2024-02-20T19:59:25.907821-05:00 | ||
custom: | ||
Author: michelleark | ||
Issue: "987" |
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,8 @@ | ||
{% macro spark__safe_cast(field, type) %} | ||
{%- set field_clean = field.strip('"').strip("'") if (cast_from_string_unsupported_for(type) and field is string) else field -%} | ||
cast({{field_clean}} as {{type}}) | ||
{% endmacro %} | ||
|
||
{% macro cast_from_string_unsupported_for(type) %} | ||
{{ return(type.lower().startswith('struct') or type.lower().startswith('array') or type.lower().startswith('map')) }} | ||
{% endmacro %} |
34 changes: 34 additions & 0 deletions
34
tests/functional/adapter/unit_testing/test_unit_testing.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 @@ | ||
import pytest | ||
|
||
from dbt.tests.adapter.unit_testing.test_types import BaseUnitTestingTypes | ||
from dbt.tests.adapter.unit_testing.test_case_insensitivity import BaseUnitTestCaseInsensivity | ||
from dbt.tests.adapter.unit_testing.test_invalid_input import BaseUnitTestInvalidInput | ||
|
||
|
||
class TestSparkUnitTestingTypes(BaseUnitTestingTypes): | ||
@pytest.fixture | ||
def data_types(self): | ||
# sql_value, yaml_value | ||
return [ | ||
["1", "1"], | ||
["2.0", "2.0"], | ||
["'12345'", "12345"], | ||
["'string'", "string"], | ||
["true", "true"], | ||
["date '2011-11-11'", "2011-11-11"], | ||
["timestamp '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], | ||
["array(1, 2, 3)", "'array(1, 2, 3)'"], | ||
[ | ||
"map('10', 't', '15', 'f', '20', NULL)", | ||
"""'map("10", "t", "15", "f", "20", NULL)'""", | ||
], | ||
['named_struct("a", 1, "b", 2, "c", 3)', """'named_struct("a", 1, "b", 2, "c", 3)'"""], | ||
] | ||
|
||
|
||
class TestSparkUnitTestCaseInsensitivity(BaseUnitTestCaseInsensivity): | ||
pass | ||
|
||
|
||
class TestSparkUnitTestInvalidInput(BaseUnitTestInvalidInput): | ||
pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity, I believe this change was made to avoid including the database and schema when rendering the create statement for a view, which was necessary by the unit testing framework.
I believe it could be implemented more precisely by the changes here: https://github.com/dbt-labs/dbt-spark/pull/978/files#diff-786bb6587e86e50a2d01888eb2d4a5257e9a0025f75379214fa93cd5a033c9fbR141