forked from dbt-labs/metricflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for
Dimension(...).grain(...)
in where filter (dbt-labs#785)
This PR adds support for the Dimension(...).grain(...) syntax for the where parameter and filter spec by using the factory pattern & implementing the Query Interface protocols.
- Loading branch information
1 parent
21b03b7
commit e1381ea
Showing
7 changed files
with
138 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Support for the Dimension(...).grain(...) syntax for the where parameter | ||
time: 2023-10-04T10:22:55.730467-05:00 | ||
custom: | ||
Author: DevonFulcher | ||
Issue: None |
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,54 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Sequence | ||
|
||
from dbt_semantic_interfaces.call_parameter_sets import ( | ||
DimensionCallParameterSet, | ||
FilterCallParameterSets, | ||
TimeDimensionCallParameterSet, | ||
) | ||
from dbt_semantic_interfaces.naming.dundered import DunderedNameFormatter | ||
from dbt_semantic_interfaces.references import DimensionReference, EntityReference, TimeDimensionReference | ||
from dbt_semantic_interfaces.type_enums import TimeGranularity | ||
|
||
from metricflow.specs.specs import DimensionSpec, TimeDimensionSpec | ||
|
||
|
||
class DimensionSpecResolver: | ||
"""Resolves specs for Dimension & TimeDimension given name, grain, & entity path. Utilized in where clause in Jinja syntax.""" | ||
|
||
def __init__(self, call_parameter_sets: FilterCallParameterSets): # noqa | ||
self._call_parameter_sets = call_parameter_sets | ||
|
||
def resolve_dimension_spec(self, name: str, entity_path: Sequence[str]) -> DimensionSpec: | ||
"""Resolve Dimension spec with the call_parameter_sets.""" | ||
structured_name = DunderedNameFormatter.parse_name(name) | ||
call_parameter_set = DimensionCallParameterSet( | ||
dimension_reference=DimensionReference(element_name=structured_name.element_name), | ||
entity_path=( | ||
tuple(EntityReference(element_name=arg) for arg in entity_path) + structured_name.entity_links | ||
), | ||
) | ||
return DimensionSpec( | ||
element_name=call_parameter_set.dimension_reference.element_name, | ||
entity_links=call_parameter_set.entity_path, | ||
) | ||
|
||
def resolve_time_dimension_spec( | ||
self, name: str, time_granularity_name: TimeGranularity, entity_path: Sequence[str] | ||
) -> TimeDimensionSpec: | ||
"""Resolve TimeDimension spec with the call_parameter_sets.""" | ||
structured_name = DunderedNameFormatter.parse_name(name) | ||
call_parameter_set = TimeDimensionCallParameterSet( | ||
time_dimension_reference=TimeDimensionReference(element_name=structured_name.element_name), | ||
time_granularity=time_granularity_name, | ||
entity_path=( | ||
tuple(EntityReference(element_name=arg) for arg in entity_path) + structured_name.entity_links | ||
), | ||
) | ||
assert call_parameter_set in self._call_parameter_sets.time_dimension_call_parameter_sets | ||
return TimeDimensionSpec( | ||
element_name=call_parameter_set.time_dimension_reference.element_name, | ||
entity_links=call_parameter_set.entity_path, | ||
time_granularity=call_parameter_set.time_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
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 was deleted.
Oops, something went wrong.