Add 'metric_time' compatibility to metric filters#1658
Add 'metric_time' compatibility to metric filters#1658wtremml18 wants to merge 6 commits intodbt-labs:mainfrom
Conversation
|
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR. CLA has not been signed by users: @wtremml18 |
|
Hey @wtremml18! Thanks so much for the contribution!
I think you're looking to unblock a specific use case, can you clarify what that is so we can help make sure this is shaping up to the right result? I.e., what is an example query and expected result you're looking for? |
|
Thanks @courtneyholcomb ! I have more details in this issue The gist is that we need metric filters to respect past dates so we can calculate things like:
These are a couple examples, but you can see how querying metrics like these would lead to unexpected results because the metric filters use 'all-time' |
|
@courtneyholcomb - almost a year later, I have two PRs! These are passing locally and behave as expected in both jaffle-sl-template and Klaviyo's production dbt project. MetricFlow PR: #1965 |
Description
This Pull Request updates metric-filter handling and associated tests to support filters on metrics that include multiple group_by items—especially the special case where one of them is metric_time. For example:
This allows the
sl query --metrics <metric_with_filter> --group-by metric_time__monthto return time-bucketed results rather than filtering for all-time. This is especially important for business metrics filtered to something like "paid users"Key Changes
Allow Multiple Items in group_by:
GroupByMetricPattern.from_call_parameter_setintyped_patterns.pyto parse all group_by entries, no longer forcing a single item. Likely need to validate that this doesn't cause fan-out joins.metric_timeis among thegroup_byitems, we treat it as a valid dimension link for the metric.This is the using the "Everything is an Entity" approach :/
How to Use
With these changes, you can now write filters or expressions that respect the parent metric's group_by granularity:
Potential Shortcomings / Future Considerations
Verbose Column Names:
Performance of Multiple Group‑Bys:
typed_patterns.pydoes not cause unexpected query bloat.metric_time Semantics:
Backward Compatibility:
Testing
test_metric_in_filter_with_metric_timeensures that 'listing' plus 'metric_time' in group_by is resolved properly.Note that I wanted to get feedback before extending my changes in 'metricflow-semantics' before extending it to 'metricflow'.
After reviewing a few PRs, it's not quite clear which new tests are required. I see the original PR for enabling metrics in filters was pretty sparse as compared with the extensive integration tests in other PRs.