Skip to content

Commit

Permalink
Normalizing data type on schema changes test.
Browse files Browse the repository at this point in the history
  • Loading branch information
elongl committed Sep 27, 2023
1 parent 2fd9b2c commit bdc18a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions integration_tests/tests/test_schema_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
from dbt_project import DbtProject

DATASET1 = [
{"id": 1, "name": "Elon"},
{"id": 1, "name": "Elon", "nick": "EGK"},
{"id": 2, "name": "Itamar"},
{"id": 3, "name": "Ofek"},
]

DATASET2 = [
{"id": "a", "first_name": "Elon", "age": 22},
{"id": "a", "first_name": "Elon", "age": 22, "nick": "EGK"},
{"id": "b", "first_name": "Itamar", "age": None},
{"id": "c", "first_name": "Ofek", "age": None},
]

EXPECTED_FAILURES = [
"column_added", # first_name
"column_added", # age
"type_changed", # id
"column_removed", # name
("first_name", "column_added"),
("age", "column_added"),
("id", "type_changed"),
("name", "column_removed"),
]


def assert_test_results(test_results: List[dict]):
expected_failures = EXPECTED_FAILURES.copy()
for test_result in test_results:
test_sub_type = test_result["test_sub_type"]
assert test_result["status"] == "fail" and test_sub_type in expected_failures
expected_failures.remove(test_sub_type)
failed_test_results = [
test_result for test_result in test_results if test_result["status"] == "fail"
]
assert len(failed_test_results) == len(expected_failures)

for test_result in failed_test_results:
test_failure = (
test_result["column_name"].lower(),
test_result["test_sub_type"].lower(),
)
expected_failures.remove(test_failure)
assert not expected_failures


Expand All @@ -55,6 +62,7 @@ def test_schema_changes_from_baseline(test_id: str, dbt_project: DbtProject):
columns=[
{"name": "id", "data_type": "integer"},
{"name": "name", "data_type": "string"},
{"name": "nick", "data_type": "string"},
],
data=DATASET2,
multiple_results=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% for column in columns %}
select
{{ elementary.edr_cast_as_string(elementary.edr_quote(column.name)) }} as column_name,
{{ elementary.edr_cast_as_string(elementary.edr_quote(column.data_type)) }} as data_type
{{ elementary.edr_cast_as_string(elementary.edr_quote(elementary.get_normalized_data_type(column.dtype))) }} as data_type
{% if not loop.last %}
union all
{% endif %}
Expand Down

0 comments on commit bdc18a6

Please sign in to comment.