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

add ability to select models by access #7739

Merged
merged 3 commits into from
Jun 1, 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
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