Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
adding pre-commit changes
  • Loading branch information
callum-mcdata committed Aug 4, 2022
commit 13e8941b01261e232e67cee1768859f088fd6a16
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ venv/

# poetry
pyproject.toml
poetry.lock
poetry.lock
18 changes: 9 additions & 9 deletions core/dbt/contracts/graph/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,40 @@ def parent_metrics_names(cls, metric_node, manifest):
@classmethod
def reverse_dag_parsing(cls, metric_node, manifest, metric_depth_count):
if metric_node.type == "expression":
yield {metric_node.name:metric_depth_count}
metric_depth_count = metric_depth_count+1
yield {metric_node.name: metric_depth_count}
metric_depth_count = metric_depth_count + 1

for parent_unique_id in metric_node.depends_on.nodes:
node = manifest.metrics.get(parent_unique_id)
if node and node.resource_type == NodeType.Metric and node.type == "expression":
yield from cls.reverse_dag_parsing(node, manifest, metric_depth_count)

def full_metric_dependency(self):
to_return = list(set(self.parent_metrics_names(self.node, self.manifest)))
return to_return

def base_metric_dependency(self):
in_scope_metrics = list(self.parent_metrics(self.node, self.manifest))

to_return =[]
to_return = []
for metric in in_scope_metrics:
if metric.type != "expression" and metric.name not in to_return:
to_return.append(metric.name)

return to_return

def derived_metric_dependency(self):
in_scope_metrics = list(self.parent_metrics(self.node, self.manifest))

to_return =[]
to_return = []
for metric in in_scope_metrics:
if metric.type == "expression" and metric.name not in to_return:
to_return.append(metric.name)

return to_return

def derived_metric_dependency_depth(self):
metric_depth_count = 1
to_return = list(self.reverse_dag_parsing(self.node, self.manifest,metric_depth_count))
to_return = list(self.reverse_dag_parsing(self.node, self.manifest, metric_depth_count))

return to_return
return to_return
13 changes: 4 additions & 9 deletions tests/functional/metrics/test_metric_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,23 @@ def test_expression_metric(
manifest = get_manifest(project.project_root)
parsed_metric = manifest.metrics["metric.test.average_tenure_plus_one"]
testing_metric = ResolvedMetricReference(parsed_metric, manifest, None)



full_metric_dependency = set(testing_metric.full_metric_dependency())
expected_full_metric_dependency = set(
["average_tenure_plus_one", "average_tenure", "collective_tenure", "number_of_people"]
)
assert full_metric_dependency == expected_full_metric_dependency

base_metric_dependency = set(testing_metric.base_metric_dependency())
expected_base_metric_dependency = set(
["collective_tenure", "number_of_people"]
)
expected_base_metric_dependency = set(["collective_tenure", "number_of_people"])
assert base_metric_dependency == expected_base_metric_dependency

derived_metric_dependency = set(testing_metric.derived_metric_dependency())
expected_derived_metric_dependency = set(
["average_tenure_plus_one", "average_tenure"]
)
expected_derived_metric_dependency = set(["average_tenure_plus_one", "average_tenure"])
assert derived_metric_dependency == expected_derived_metric_dependency

derived_metric_dependency_depth = list(testing_metric.derived_metric_dependency_depth())
expected_derived_metric_dependency_depth = list(
[{"average_tenure_plus_one":1}, {"average_tenure":2}]
[{"average_tenure_plus_one": 1}, {"average_tenure": 2}]
)
assert derived_metric_dependency_depth == expected_derived_metric_dependency_depth