-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional tests for unit testing (#976)
- Loading branch information
1 parent
613fa58
commit ef91425
Showing
4 changed files
with
49 additions
and
0 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,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 |