-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* wip * More support for ratio metrics * Formatting and linting * Fix unit tests * Support disabling metrics * mypy * address all TODOs * make pypy happy * wip * checkpoint * refactor, remove ratio_terms * flake8 and unit tests * remove debugger * quickfix for filters * Experiment with functional testing for 'expression' metrics * reformatting slightly * make file and mypy fix * remove config from metrics - wip * add metrics back to context * adding test changes * fixing test metrics * revert name audit * pre-commit fixes * add changelog * Bumping manifest version to v6 (#5430) * Bumping manifest version to v6 * Adding manifest file for tests * Reverting unneeded changes * Updating v6 * Updating test to add metrics field * Adding changelog * add v5 to backwards compatibility * Clean up test_previous_version_state, update for v6 (#5440) * Update test_previous_version_state for v6. Cleanup * Regenerate, rm breakpoint * Code checks * Add assertion that will fail when we bump manifest version * update tests to automatically tests all previous versions Co-authored-by: Emily Rockman <[email protected]> Co-authored-by: Jeremy Cohen <[email protected]> Co-authored-by: Callum McCann <[email protected]> Co-authored-by: Emily Rockman <[email protected]> Co-authored-by: leahwicz <[email protected]>
- Loading branch information
1 parent
febbd97
commit 064d890
Showing
33 changed files
with
7,070 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Features | ||
body: Add support for ratio metrics | ||
time: 2022-07-05T08:30:26.494837-05:00 | ||
custom: | ||
Author: drewbanin callum-mcdata | ||
Issue: "4884" | ||
PR: "5027" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Under the Hood | ||
body: Bump manifest version to v6 | ||
time: 2022-07-05T14:21:20.66768-04:00 | ||
custom: | ||
Author: leahwicz | ||
Issue: "5417" | ||
PR: "5430" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from dbt.node_types import NodeType | ||
|
||
|
||
class MetricReference(object): | ||
def __init__(self, metric_name, package_name=None): | ||
self.metric_name = metric_name | ||
self.package_name = package_name | ||
|
||
def __str__(self): | ||
return f"{self.metric_name}" | ||
|
||
|
||
class ResolvedMetricReference(MetricReference): | ||
""" | ||
Simple proxy over a ParsedMetric which delegates property | ||
lookups to the underlying node. Also adds helper functions | ||
for working with metrics (ie. __str__ and templating functions) | ||
""" | ||
|
||
def __init__(self, node, manifest, Relation): | ||
super().__init__(node.name, node.package_name) | ||
self.node = node | ||
self.manifest = manifest | ||
self.Relation = Relation | ||
|
||
def __getattr__(self, key): | ||
return getattr(self.node, key) | ||
|
||
def __str__(self): | ||
return f"{self.node.name}" | ||
|
||
@classmethod | ||
def parent_metrics(cls, metric_node, manifest): | ||
yield metric_node | ||
|
||
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: | ||
yield from cls.parent_metrics(node, manifest) | ||
|
||
def parent_models(self): | ||
in_scope_metrics = list(self.parent_metrics(self.node, self.manifest)) | ||
|
||
to_return = { | ||
"base": [], | ||
"derived": [], | ||
} | ||
for metric in in_scope_metrics: | ||
if metric.type == "expression": | ||
to_return["derived"].append( | ||
{"metric_source": None, "metric": metric, "is_derived": True} | ||
) | ||
else: | ||
for node_unique_id in metric.depends_on.nodes: | ||
node = self.manifest.nodes.get(node_unique_id) | ||
if node and node.resource_type in NodeType.refable(): | ||
to_return["base"].append( | ||
{ | ||
"metric_relation_node": node, | ||
"metric_relation": self.Relation.create( | ||
database=node.database, | ||
schema=node.schema, | ||
identifier=node.alias, | ||
), | ||
"metric": metric, | ||
"is_derived": False, | ||
} | ||
) | ||
|
||
return to_return |
Oops, something went wrong.