-
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.
GroupByMetrics are allowed in filters, but not in group by items. Use new pattern to distinguish the two.
- Loading branch information
1 parent
49ff11f
commit 4f5244f
Showing
2 changed files
with
33 additions
and
6 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
29 changes: 29 additions & 0 deletions
29
metricflow-semantics/metricflow_semantics/specs/patterns/no_group_by_metric.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,29 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, Sequence | ||
|
||
from typing_extensions import override | ||
|
||
from metricflow_semantics.specs.patterns.spec_pattern import SpecPattern | ||
from metricflow_semantics.specs.spec_classes import ( | ||
InstanceSpec, | ||
LinkableInstanceSpec, | ||
) | ||
from metricflow_semantics.specs.spec_set import group_specs_by_type | ||
|
||
|
||
class NoGroupByMetricPattern(SpecPattern): | ||
"""Matches to linkable specs, but only if they're not group by metrics. | ||
Group by metrics are allowed in filters but not in the query input group by. | ||
""" | ||
|
||
@override | ||
def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[LinkableInstanceSpec]: | ||
specs_to_return: List[LinkableInstanceSpec] = [] | ||
spec_set = group_specs_by_type(candidate_specs) | ||
specs_to_return.extend(spec_set.time_dimension_specs) | ||
specs_to_return.extend(spec_set.dimension_specs) | ||
specs_to_return.extend(spec_set.entity_specs) | ||
|
||
return specs_to_return |