-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix not equals comparison to be null-safe for adapters/utils tests #7776
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a3d98d
Fix names within functional test
dbeatty10 9b91b7d
Changelog entry
dbeatty10 617cf1e
Test for implementation of null-safe equals comparison
dbeatty10 dfd9ce6
Remove duplicated where filter
dbeatty10 7a1b395
Fix null-safe equals comparison
dbeatty10 494753c
Fix tests for `concat` and `hash` by using empty strings () instead o…
dbeatty10 9aca97a
Remove macro namespace interpolation
dbeatty10 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,71 @@ | ||
| 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, | ||
| } | ||
|
|
||
| # make it possible to dynamically update the macro call with a namespace | ||
| # (e.g.) 'dateadd', 'dbt.dateadd', 'dbt_utils.dateadd' | ||
| def macro_namespace(self): | ||
| return "" | ||
|
|
||
| def interpolate_macro_namespace(self, model_sql, macro_name): | ||
dbeatty10 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| macro_namespace = self.macro_namespace() | ||
| return ( | ||
| model_sql.replace(f"{macro_name}(", f"{macro_namespace}.{macro_name}(") | ||
| if macro_namespace | ||
| else model_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": self.interpolate_macro_namespace( | ||
| MODELS__EQUAL_VALUES_SQL, "equals" | ||
| ), | ||
| "not_equal_values.sql": self.interpolate_macro_namespace( | ||
| MODELS__NOT_EQUAL_VALUES_SQL, "equals" | ||
| ), | ||
| } | ||
|
|
||
| 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.