Skip to content

Commit

Permalink
Modified dimensions_for_metric to allow for returning more details (#737
Browse files Browse the repository at this point in the history
)

modified dimension_for_metric to allow returning a list of repeating dimensions with different time granularity
  • Loading branch information
WilliamDee authored Aug 28, 2023
1 parent 5497ea3 commit 652ba21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
23 changes: 14 additions & 9 deletions metricflow/engine/metricflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,17 @@ def explain(
pass

@abstractmethod
def simple_dimensions_for_metrics(self, metric_names: List[str]) -> List[Dimension]:
def simple_dimensions_for_metrics(
self, metric_names: List[str], without_any_property: Sequence[LinkableElementProperties]
) -> List[Dimension]:
"""Retrieves a list of all common dimensions for metric_names.
"simple" dimensions are the ones that people expect from a UI perspective. For example, if "ds" is a time
dimension at a day granularity, this would not list "ds__week".
Args:
metric_names: Names of metrics to get common dimensions from.
without_any_property: Return dimensions not matching these properties.
Returns:
A list of Dimension objects containing metadata.
Expand Down Expand Up @@ -491,17 +494,19 @@ def _create_execution_plan(self, mf_query_request: MetricFlowQueryRequest) -> Me
def explain(self, mf_request: MetricFlowQueryRequest) -> MetricFlowExplainResult: # noqa: D
return self._create_execution_plan(mf_request)

def simple_dimensions_for_metrics(self, metric_names: List[str]) -> List[Dimension]: # noqa: D
def simple_dimensions_for_metrics( # noqa: D
self,
metric_names: List[str],
without_any_property: Sequence[LinkableElementProperties] = (
LinkableElementProperties.ENTITY,
LinkableElementProperties.DERIVED_TIME_GRANULARITY,
LinkableElementProperties.LOCAL_LINKED,
),
) -> List[Dimension]:
path_key_to_linkable_dimensions = (
self._semantic_manifest_lookup.metric_lookup.linkable_set_for_metrics(
metric_references=[MetricReference(element_name=mname) for mname in metric_names],
without_any_property=frozenset(
{
LinkableElementProperties.ENTITY,
LinkableElementProperties.DERIVED_TIME_GRANULARITY,
LinkableElementProperties.LOCAL_LINKED,
}
),
without_any_property=frozenset(without_any_property),
)
).path_key_to_linkable_dimensions

Expand Down
9 changes: 8 additions & 1 deletion metricflow/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from typing import List, Optional, Sequence

from dbt_semantic_interfaces.implementations.elements.dimension import PydanticDimensionTypeParams
from dbt_semantic_interfaces.protocols.dimension import (
Dimension as SemanticManifestDimension,
)
Expand Down Expand Up @@ -78,12 +79,18 @@ def from_pydantic(cls, pydantic_dimension: SemanticManifestDimension, path_key:
element_name=path_key.element_name,
entity_links=path_key.entity_links,
).qualified_name
parsed_type_params: Optional[DimensionTypeParams] = None
if pydantic_dimension.type_params:
parsed_type_params = PydanticDimensionTypeParams(
time_granularity=path_key.time_granularity,
validity_params=pydantic_dimension.type_params.validity_params,
)
return cls(
name=pydantic_dimension.name,
qualified_name=qualified_name,
description=pydantic_dimension.description,
type=pydantic_dimension.type,
type_params=pydantic_dimension.type_params,
type_params=parsed_type_params,
metadata=pydantic_dimension.metadata,
is_partition=pydantic_dimension.is_partition,
expr=pydantic_dimension.expr,
Expand Down

0 comments on commit 652ba21

Please sign in to comment.