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 default_granularity to metric spec #291

Merged
merged 6 commits into from
Jun 28, 2024
Merged

Conversation

courtneyholcomb
Copy link
Contributor

@courtneyholcomb courtneyholcomb commented Jun 14, 2024

Resolves #290

Description

Now that we are enabling sub-daily granularities, the current behavior of metric_time will likely be unexpected to users. If they change any of their time dimensions to use a grain smaller than DAY, metric_time will default to that grain. To avoid this confusion, add a parameter that allows users to choose which grain they want their metric to default to. This will default to DAY if not set to avoid the unexpected behavior change. (If DAY is smaller than the defined granularity, will default to the smallest available granularity.)

Checklist

@cla-bot cla-bot bot added the cla:yes label Jun 14, 2024
@dbt-labs dbt-labs deleted a comment from github-actions bot Jun 14, 2024
@courtneyholcomb courtneyholcomb marked this pull request as ready for review June 15, 2024 19:21
Base automatically changed from court/cumulative-params to main June 18, 2024 22:59
@tlento
Copy link
Collaborator

tlento commented Jun 20, 2024

I think this branch needs an update, will hold off until the cumulative metrics pieces are through.

@courtneyholcomb courtneyholcomb changed the title Add default_grain to metric spec Add default_granularity to metric spec Jun 27, 2024
@@ -228,3 +238,31 @@ def input_metrics(self) -> Sequence[PydanticMetricInput]:
return (self.type_params.numerator, self.type_params.denominator)
else:
assert_values_exhausted(self.type)

@staticmethod
def all_input_measures_for_metric(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method be in the protocol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not. I don't think we want to require implementing this logic any place that implements a metric.

measures.add(metric.type_params.measure)
elif metric.type is MetricType.DERIVED or metric.type is MetricType.RATIO:
for input_metric in metric.input_metrics:
nested_metric = metric_index.get(MetricReference(input_metric.name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just use the input_metric.as_reference property

assert (
metric.type_params.measure is not None
), f"Metric {metric.name} should have a measure defined, but it does not."
measures.add(metric.type_params.measure)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but heads up that this could end up with duplicate measures.

Ie.,
if a metric that has 2 measures is the same but has a different input filter, then the set() wouldn't count them as duplicates as the MetricInputMeasure will have a different filter field even tho it's referencing the same measure.

If you don't want duplicate measures showing up in this, you could return Set[MeasureReference] instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!!

@courtneyholcomb courtneyholcomb merged commit 1eb584b into main Jun 28, 2024
22 checks passed
@courtneyholcomb courtneyholcomb deleted the court/default-grain branch June 28, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add default_grain to metric spec
3 participants