-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't add measure-level filters to post-agg filters (#1452)
## Context We should respect filter hierarchy and have, - measure-level filters should be applied only pre-aggregation - metric-level filters and query-level filters should be applied pre AND post-aggregation Meaning, measure-level filters should not be applied post-aggregation. ### Refactor Changed `filter_specs` from being a tuple of filter specs all mashed together to a `WhereFilterSpecSet` where it stores which levels each of the filters were defined at. This was changed inside `MetricSpec` and `MetricInputMeasureSpec`. Resolves SL-2956
- Loading branch information
1 parent
15a6ae7
commit 022c88b
Showing
96 changed files
with
4,513 additions
and
1,896 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
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
46 changes: 46 additions & 0 deletions
46
metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_spec_set.py
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,46 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Tuple | ||
|
||
from dbt_semantic_interfaces.dataclass_serialization import SerializableDataclass | ||
|
||
from metricflow_semantics.specs.where_filter.where_filter_spec import WhereFilterSpec | ||
|
||
|
||
@dataclass(frozen=True) | ||
class WhereFilterSpecSet(SerializableDataclass): | ||
"""Class to encapsulate filters needed at a certain point of the queried metric. | ||
This class splits up the filters based on where it was defined at, which can then be used to | ||
determine where each filter should be applied during each step of the metric building process. | ||
measure-level: filters defined on the input_measure | ||
metric-level: filters defined on the input_metric or metric:filter | ||
query-level: filters defined at query time | ||
""" | ||
|
||
measure_level_filter_specs: Tuple[WhereFilterSpec, ...] = () | ||
metric_level_filter_specs: Tuple[WhereFilterSpec, ...] = () | ||
query_level_filter_specs: Tuple[WhereFilterSpec, ...] = () | ||
|
||
@property | ||
def after_measure_aggregation_filter_specs(self) -> Tuple[WhereFilterSpec, ...]: | ||
"""Returns filters relevant to post-measure aggregation.""" | ||
return self.metric_level_filter_specs + self.query_level_filter_specs | ||
|
||
@property | ||
def all_filter_specs(self) -> Tuple[WhereFilterSpec, ...]: | ||
"""Returns all the filters in this class. | ||
Generally, before measure aggregation, all filters should be applied. | ||
""" | ||
return self.measure_level_filter_specs + self.metric_level_filter_specs + self.query_level_filter_specs | ||
|
||
def merge(self, other: WhereFilterSpecSet) -> WhereFilterSpecSet: | ||
"""Merge 2 WhereFilterSpecSet together.""" | ||
return WhereFilterSpecSet( | ||
measure_level_filter_specs=self.measure_level_filter_specs + other.measure_level_filter_specs, | ||
metric_level_filter_specs=self.metric_level_filter_specs + other.metric_level_filter_specs, | ||
query_level_filter_specs=self.query_level_filter_specs + other.query_level_filter_specs, | ||
) |
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
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
Oops, something went wrong.