-
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.
Add ExpandedTimeGranularity struct to linkable elements (#1385)
With the impending introduction of custom granularities, which are named granularities accessed via a lookup keyed by a date/time value with a specified base grain, our reliance on raw TimeGranularity enumeration elements will no longer be sufficient for managing dataflow plans or queries. In order to be able to reference custom granularities in our TimeDimensionSpec and associated ElementPathKey and LinkableElement subclasses we need to make space for both the granularity name and a base grain value. This change adds an ExpandedTimeGranularity struct to encapsulate both of these pieces of information in a single object value, and switches the LinkableDimension time granularity property to use it in place of the bare TimeGranularity enum value. This is just the first step. Later changes will migrate most internal TimeGranularity-typed properties to the new ExpandedTimeGranularity construct. Once we have a proof of concept for this working we will decide whether this construct belongs in dbt-semantic-interfaces or if we can keep this internal to MetricFlow. The main reason to expand this is for more natural support for time windows and offsets, but we may be able to simply allow strings in the protocol spec and convert them to the struct types inside of MetricFlow.
- Loading branch information
Showing
47 changed files
with
1,734 additions
and
1,476 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
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
32 changes: 32 additions & 0 deletions
32
metricflow-semantics/metricflow_semantics/time/granularity.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,32 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from dbt_semantic_interfaces.dataclass_serialization import SerializableDataclass | ||
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ExpandedTimeGranularity(SerializableDataclass): | ||
"""Dataclass container for custom granularity extensions to the base TimeGranularity enumeration. | ||
This includes the granularity name, which is either the custom granularity or the TimeGranularity string value, | ||
and an associated base time granularity value which we use as a pointer to the base grain used to look up the | ||
time spine. This will allow for some level of comparison between custom granularities. | ||
Note: this assumes that any base TimeGranularity value will derive the name from the TimeGranularity. It might be | ||
worth adding validation to ensure that is always the case, meaning that no `name` value can be a value in the | ||
TimeGranularity enumeration. | ||
""" | ||
|
||
name: str | ||
base_granularity: TimeGranularity | ||
|
||
@property | ||
def is_custom_granularity(self) -> bool: # noqa: D102 | ||
return self.base_granularity.value != self.name | ||
|
||
@classmethod | ||
def from_time_granularity(cls, granularity: TimeGranularity) -> ExpandedTimeGranularity: | ||
"""Factory method for creating an ExpandedTimeGranularity from a standard TimeGranularity enumeration value.""" | ||
return ExpandedTimeGranularity(name=granularity.value, base_granularity=granularity) |
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.