-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix not equals comparison to be null-safe for adapters/utils tests (#…
…7776) * Fix names within functional test * Changelog entry * Test for implementation of null-safe equals comparison * Remove duplicated where filter * Fix null-safe equals comparison * Fix tests for `concat` and `hash` by using empty strings () instead of `null` * Remove macro namespace interpolation
- Loading branch information
Showing
8 changed files
with
147 additions
and
13 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: Fixes | ||
body: Fix null-safe equals comparison via `equals` | ||
time: 2023-06-04T08:00:52.537967-06:00 | ||
custom: | ||
Author: dbeatty10 | ||
Issue: "7778" |
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,41 @@ | ||
# equals | ||
|
||
SEEDS__DATA_EQUALS_CSV = """key_name,x,y,expected | ||
1,1,1,same | ||
2,1,2,different | ||
3,1,null,different | ||
4,2,1,different | ||
5,2,2,same | ||
6,2,null,different | ||
7,null,1,different | ||
8,null,2,different | ||
9,null,null,same | ||
""" | ||
|
||
|
||
MODELS__EQUAL_VALUES_SQL = """ | ||
with data as ( | ||
select * from {{ ref('data_equals') }} | ||
) | ||
select * | ||
from data | ||
where | ||
{{ equals('x', 'y') }} | ||
""" | ||
|
||
|
||
MODELS__NOT_EQUAL_VALUES_SQL = """ | ||
with data as ( | ||
select * from {{ ref('data_equals') }} | ||
) | ||
select * | ||
from data | ||
where | ||
not {{ equals('x', 'y') }} | ||
""" |
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,54 @@ | ||
import pytest | ||
from dbt.tests.adapter.utils.base_utils import macros__equals_sql | ||
from dbt.tests.adapter.utils.fixture_equals import ( | ||
SEEDS__DATA_EQUALS_CSV, | ||
MODELS__EQUAL_VALUES_SQL, | ||
MODELS__NOT_EQUAL_VALUES_SQL, | ||
) | ||
from dbt.tests.util import run_dbt, relation_from_name | ||
|
||
|
||
class BaseEquals: | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return { | ||
"equals.sql": macros__equals_sql, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"data_equals.csv": SEEDS__DATA_EQUALS_CSV, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"equal_values.sql": MODELS__EQUAL_VALUES_SQL, | ||
"not_equal_values.sql": MODELS__NOT_EQUAL_VALUES_SQL, | ||
} | ||
|
||
def test_equal_values(self, project): | ||
run_dbt(["seed"]) | ||
run_dbt(["run"]) | ||
|
||
# There are 9 cases total; 3 are equal and 6 are not equal | ||
|
||
# 3 are equal | ||
relation = relation_from_name(project.adapter, "equal_values") | ||
result = project.run_sql( | ||
f"select count(*) as num_rows from {relation} where expected = 'same'", fetch="one" | ||
) | ||
assert result[0] == 3 | ||
|
||
# 6 are not equal | ||
relation = relation_from_name(project.adapter, "not_equal_values") | ||
result = project.run_sql( | ||
f"select count(*) as num_rows from {relation} where expected = 'different'", | ||
fetch="one", | ||
) | ||
assert result[0] == 6 | ||
|
||
|
||
class TestEquals(BaseEquals): | ||
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