dbt-labs / metricflow

MetricFlow allows you to define, build, and maintain metrics in code.
https://docs.getdbt.com/docs/build/about-metricflow
Other
1.12k stars 92 forks source link

Use `MetricTimeDefaultGranularityPattern` to resolve `metric_time` granularity #1324

Closed courtneyholcomb closed 1 month ago

courtneyholcomb commented 1 month ago

This is the main behavior change for this feature. Here, we apply the MetricTimeDefaultGranularityPattern for group by and filter resolution so that metric_time defaults to the default granularity instead of the minimum one.

There is one case where we actually want the minimum granularity instead of the default granularity for metric_time, which is when determining the granularity used to adjust time constraints. The only_use_minimum_grain flag is used for that purpose.

Note that very few tests are impacted by this change because default_granularity defaults to DAY or the minimum granularity for a time dimension if it's not set on the metric. This is the same behavior as before since no time dimensions have been added to our tests with sub-daily granularity yet. In an upcoming PR I will have tests that add default_granularity to some metrics to see the changes.

You will see a handful snapshot changes here. These reflect an intentional behavior change (agreed on by product) in which we don't error if metric_time is queried for metrics with two different default granularities. Instead, we use the larger of the two default_granularities, which is guaranteed to work for both metrics.