Skip to content

Commit

Permalink
add ability to select models by access (#7739)
Browse files Browse the repository at this point in the history
* add ability to select models by access

* changie

* Update core/dbt/graph/selector_methods.py
  • Loading branch information
dave-connors-3 authored Jun 1, 2023
1 parent 45d6145 commit 9dd5ab9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230530-164847.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: add access selection syntax
time: 2023-05-30T16:48:47.740037-05:00
custom:
Author: dave-connors-3
Issue: "7738"
12 changes: 12 additions & 0 deletions core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MethodName(StrEnum):
FQN = "fqn"
Tag = "tag"
Group = "group"
Access = "access"
Source = "source"
Path = "path"
File = "file"
Expand Down Expand Up @@ -230,6 +231,16 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
yield node


class AccessSelectorMethod(SelectorMethod):
def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[UniqueId]:
"""yields model nodes matching the specified access level"""
for node, real_node in self.parsed_nodes(included_nodes):
if not isinstance(real_node, ModelNode):
continue
if selector == real_node.access:
yield node


class SourceSelectorMethod(SelectorMethod):
def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[UniqueId]:
"""yields nodes from included are the specified source."""
Expand Down Expand Up @@ -713,6 +724,7 @@ class MethodManager:
MethodName.FQN: QualifiedNameSelectorMethod,
MethodName.Tag: TagSelectorMethod,
MethodName.Group: GroupSelectorMethod,
MethodName.Access: AccessSelectorMethod,
MethodName.Source: SourceSelectorMethod,
MethodName.Path: PathSelectorMethod,
MethodName.File: FileSelectorMethod,
Expand Down
19 changes: 19 additions & 0 deletions test/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
QualifiedNameSelectorMethod,
TagSelectorMethod,
GroupSelectorMethod,
AccessSelectorMethod,
SourceSelectorMethod,
PathSelectorMethod,
FileSelectorMethod,
Expand Down Expand Up @@ -63,6 +64,7 @@ def make_model(
depends_on_macros=None,
version=None,
latest_version=None,
access=None,
):
if refs is None:
refs = []
Expand Down Expand Up @@ -121,6 +123,7 @@ def make_model(
checksum=FileHash.from_contents(""),
version=version,
latest_version=latest_version,
access=access,
)


Expand Down Expand Up @@ -921,6 +924,22 @@ def test_select_group(manifest, view_model):
assert not search_manifest_using_method(manifest, method, "not_my_group")


def test_select_access(manifest, view_model):
change_node(
manifest,
view_model.replace(
access="public",
),
)
methods = MethodManager(manifest, None)
method = methods.get_method("access", [])
assert isinstance(method, AccessSelectorMethod)
assert method.arguments == []

assert search_manifest_using_method(manifest, method, "public") == {"view_model"}
assert not search_manifest_using_method(manifest, method, "private")


def test_select_source(manifest):
methods = MethodManager(manifest, None)
method = methods.get_method("source", [])
Expand Down

0 comments on commit 9dd5ab9

Please sign in to comment.