-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/* PR_START p--query-resolution-perf 16 */ Make patterns dataclasses.
- Loading branch information
Showing
7 changed files
with
22 additions
and
9 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
13 changes: 9 additions & 4 deletions
13
metricflow-semantics/metricflow_semantics/specs/patterns/match_list_pattern.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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Sequence | ||
from dataclasses import dataclass | ||
from typing import Sequence, Tuple | ||
|
||
from typing_extensions import override | ||
|
||
from metricflow_semantics.specs.instance_spec import InstanceSpec | ||
from metricflow_semantics.specs.patterns.spec_pattern import SpecPattern | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MatchListSpecPattern(SpecPattern): | ||
"""A spec pattern that matches based on a configured list of specs. | ||
This is useful for filtering possible group-by-items to ones valid for a query. | ||
""" | ||
|
||
def __init__(self, listed_specs: Sequence[InstanceSpec]) -> None: # noqa: D107 | ||
self._listed_specs = set(listed_specs) | ||
listed_specs: Tuple[InstanceSpec, ...] | ||
|
||
@staticmethod | ||
def create(listed_specs: Sequence[InstanceSpec]) -> MatchListSpecPattern: # noqa: D102 | ||
return MatchListSpecPattern(tuple(listed_specs)) | ||
|
||
@override | ||
def match(self, candidate_specs: Sequence[InstanceSpec]) -> Sequence[InstanceSpec]: | ||
return tuple(spec for spec in candidate_specs if spec in self._listed_specs) | ||
return tuple(spec for spec in candidate_specs if spec in self.listed_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