-
Notifications
You must be signed in to change notification settings - Fork 157
Add dimension_lookup to ModelObjectLookup
#1907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
plypaul
wants to merge
1
commit into
main
Choose a base branch
from
p/misc__02
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−25
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
metricflow-semantics/metricflow_semantics/experimental/dsi/dimension_lookup.py
This file contains hidden or 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,39 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections.abc import Mapping | ||
| from functools import cached_property | ||
| from typing import Iterable | ||
|
|
||
| from dbt_semantic_interfaces.protocols import Dimension | ||
| from dbt_semantic_interfaces.type_enums import DimensionType | ||
| from typing_extensions import override | ||
|
|
||
| from metricflow_semantics.mf_logging.attribute_pretty_format import AttributeMapping, AttributePrettyFormattable | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DimensionLookup(AttributePrettyFormattable): | ||
| """A lookup for entities within a semantic model.""" | ||
|
|
||
| def __init__(self, dimensions: Iterable[Dimension]) -> None: # noqa: D107 | ||
| self._dimensions = tuple(dimensions) | ||
|
|
||
| @cached_property | ||
| def dimension_name_to_dimension(self) -> Mapping[str, Dimension]: # noqa: D102 | ||
| return {dimension.name: dimension for dimension in self._dimensions} | ||
|
|
||
| @cached_property | ||
| def dimension_name_to_type(self) -> Mapping[str, DimensionType]: # noqa: D102 | ||
| return { | ||
| dimension_name: dimension.type for dimension_name, dimension in self.dimension_name_to_dimension.items() | ||
| } | ||
|
|
||
| @cached_property | ||
| @override | ||
| def _attribute_mapping(self) -> AttributeMapping: | ||
| return dict( | ||
| **super()._attribute_mapping, | ||
| **{attribute_name: getattr(self, attribute_name) for attribute_name in ("dimension_name_to_type",)}, | ||
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our primary entity validation seems to only guarantee that semantic models with dimensions have a primary entity (i.e., if you have a model with entities only it doesn't need to have a primary entity). Can we update this code to avoid erroring if we encounter a model like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not have any tests for this type of model, might be good to add one!