Skip to content

Commit

Permalink
[CT-2551] Make state selection MECE (#7773)
Browse files Browse the repository at this point in the history
* ct-2551: adds old and unmodified state selection methods

* ct-2551: update check_unmodified_content to simplify

* add unit and integration tests for unmodified and old

* add changelog entry

* ct-2551: reformatting of contingent adapter assignment list
  • Loading branch information
trouze authored Jun 30, 2023
1 parent 5d93780 commit adcf8bc
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20230603-141625.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: This change adds new selector methods to the state selector. Namely, state:unmodified
and state:old.
time: 2023-06-03T14:16:25.249884-05:00
custom:
Author: trouze
Issue: "7564"
13 changes: 12 additions & 1 deletion core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ def check_modified_content(
upstream_macro_change = self.check_macros_modified(new)
return different_contents or upstream_macro_change

def check_unmodified_content(
self, old: Optional[SelectorTarget], new: SelectorTarget, adapter_type: str
) -> bool:
return not self.check_modified_content(old, new, adapter_type)

def check_modified_macros(self, old, new: SelectorTarget) -> bool:
return self.check_macros_modified(new)

Expand Down Expand Up @@ -586,8 +591,10 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
state_checks = {
# it's new if there is no old version
"new": lambda old, new: old is None,
"old": lambda old, new: old is not None,
# use methods defined above to compare properties of old + new
"modified": self.check_modified_content,
"unmodified": self.check_unmodified_content,
"modified.body": self.check_modified_factory("same_body"),
"modified.configs": self.check_modified_factory("same_config"),
"modified.persisted_descriptions": self.check_modified_factory(
Expand Down Expand Up @@ -619,7 +626,11 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
previous_node = manifest.metrics[node]

keyword_args = {}
if checker.__name__ in ["same_contract", "check_modified_content"]:
if checker.__name__ in [
"same_contract",
"check_modified_content",
"check_unmodified_content",
]:
keyword_args["adapter_type"] = adapter_type # type: ignore

if checker(previous_node, real_node, **keyword_args): # type: ignore
Expand Down
Loading

0 comments on commit adcf8bc

Please sign in to comment.