-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
(#4884) Add support for ratio metrics #5027
Merged
Merged
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
72cad80
wip
drewbanin cf23d65
Merge branch 'main' of github.com:fishtown-analytics/dbt into feature…
drewbanin d43e859
Merge branch 'main' into feature/metric-improvements
drewbanin 8dcfeb1
More support for ratio metrics
drewbanin aae1c81
Formatting and linting
drewbanin 4d4198c
Fix unit tests
drewbanin a57d3b0
Support disabling metrics
drewbanin 395393e
mypy
drewbanin 55e7ab7
address all TODOs
drewbanin a9e839e
make pypy happy
drewbanin 3a8385b
Merge branch 'main' into feature/metric-improvements
drewbanin db35e88
wip
drewbanin d6e886c
checkpoint
drewbanin 7af4c51
refactor, remove ratio_terms
drewbanin 32c3c53
flake8 and unit tests
drewbanin 0344a20
remove debugger
drewbanin bee3eea
quickfix for filters
drewbanin 934605e
Experiment with functional testing for 'expression' metrics
jtcohen6 06eb926
reformatting slightly
callum-mcdata 4461d7a
make file and mypy fix
emmyoop 31cfa7f
remove config from metrics - wip
emmyoop 60ef314
add metrics back to context
emmyoop cd957a6
adding test changes
callum-mcdata ba3a78c
fixing test metrics
callum-mcdata 54c38d0
revert name audit
emmyoop 7b03989
Merge branch 'feature/metric-improvements' of https://github.com/dbt-…
emmyoop 46679e2
pre-commit fixes
emmyoop b8a7f99
add changelog
emmyoop e235ab7
Bumping manifest version to v6 (#5430)
leahwicz c28628f
Merge branch 'main' of https://github.com/dbt-labs/dbt-core into feat…
emmyoop 68f7708
add v5 to backwards compatibility
emmyoop e808272
Clean up test_previous_version_state, update for v6 (#5440)
jtcohen6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my take on a class analogous to the
Relation
object. I figured that this kind of object could be returned from themetric()
function. It would help us avoid the need to find the metric in thegraph
manually like we do hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove
.metric_value
based on conversation here.