Skip to content
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

[CT-2551] Make state selection MECE #7773

Merged
merged 6 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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