-
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.
Loading status checks…
Consolidate property filters into a class (#1441)
The signature of a few functions in `ValidLinkableSpecResolver` take in a few arguments that describe how to filter the returned items based on properties. To simplify the signatures and enable improved caching in a later PR, this PR groups them into the `LinkableElementFilter` class.
Showing
9 changed files
with
121 additions
and
86 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
metricflow-semantics/metricflow_semantics/model/semantics/element_filter.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,31 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import FrozenSet | ||
|
||
from typing_extensions import Self, override | ||
|
||
from metricflow_semantics.collection_helpers.merger import Mergeable | ||
from metricflow_semantics.model.linkable_element_property import LinkableElementProperty | ||
|
||
|
||
@dataclass(frozen=True) | ||
class LinkableElementFilter(Mergeable): | ||
"""Describes a way to filter the `LinkableElements` in a `LinkableElementSet`.""" | ||
|
||
with_any_of: FrozenSet[LinkableElementProperty] = LinkableElementProperty.all_properties() | ||
without_any_of: FrozenSet[LinkableElementProperty] = frozenset() | ||
without_all_of: FrozenSet[LinkableElementProperty] = frozenset() | ||
|
||
@override | ||
def merge(self: Self, other: LinkableElementFilter) -> LinkableElementFilter: | ||
return LinkableElementFilter( | ||
with_any_of=self.with_any_of.union(other.with_any_of), | ||
without_any_of=self.without_any_of.union(other.without_any_of), | ||
without_all_of=self.without_all_of.union(other.without_all_of), | ||
) | ||
|
||
@classmethod | ||
@override | ||
def empty_instance(cls) -> LinkableElementFilter: | ||
return LinkableElementFilter() |
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
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.