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

versioned node selection with underscore delimiting #7995

Merged
merged 5 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230629-135758.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support '_'-delimited fqn matching for versioned models and matching on Path.stem for path selection
time: 2023-06-29T13:57:58.38283-04:00
custom:
Author: michelleark
Issue: "7639"
6 changes: 4 additions & 2 deletions core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def is_selected_node(fqn: List[str], node_selector: str, is_versioned: bool) ->
flat_node_selector = node_selector.split(".")
if fqn[-2] == node_selector:
return True
# If this is a versioned model, then the last two segments should be allowed to exactly match
elif fqn[-2:] == flat_node_selector[-2:]:
# If this is a versioned model, then the last two segments should be allowed to exactly match on either the '.' or '_' delimiter
elif "_".join(fqn[-2:]) == "_".join(flat_node_selector[-2:]):
return True
else:
if fqn[-1] == node_selector:
Expand Down Expand Up @@ -351,6 +351,8 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
for node, real_node in self.all_nodes(included_nodes):
if fnmatch(Path(real_node.original_file_path).name, selector):
yield node
elif fnmatch(Path(real_node.original_file_path).stem, selector):
yield node


class PackageSelectorMethod(SelectorMethod):
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,14 @@ def test_select_fqn(manifest):
assert search_manifest_using_method(manifest, method, "versioned_model.v1") == {
"versioned_model.v1"
}
# version selection with _ instead of '.'
assert search_manifest_using_method(manifest, method, "versioned_model_v1") == {
"versioned_model.v1"
}
# version selection with _ instead of '.' - latest version
assert search_manifest_using_method(manifest, method, "versioned_model_v2") == {
"versioned_model.v2"
}
# wildcards
assert search_manifest_using_method(manifest, method, "*.*.*_model") == {
"mynamespace.union_model",
Expand Down Expand Up @@ -1020,6 +1028,15 @@ def test_select_file(manifest):
assert not search_manifest_using_method(manifest, method, "missing.py")
assert search_manifest_using_method(manifest, method, "table_*.csv") == {"table_model_csv"}

# stem selector match
assert search_manifest_using_method(manifest, method, "union_model") == {
"union_model",
"mynamespace.union_model",
}
assert search_manifest_using_method(manifest, method, "versioned_model_v1") == {
"versioned_model.v1"
}


def test_select_package(manifest):
methods = MethodManager(manifest, None)
Expand Down