Skip to content

Commit

Permalink
Custom granularity cleanup (#1430)
Browse files Browse the repository at this point in the history
Implements some small PR feedback from
#1425.
  • Loading branch information
courtneyholcomb authored Sep 26, 2024
1 parent ca92929 commit f175b9b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class SemanticManifestLookup:
def __init__(self, semantic_manifest: SemanticManifest) -> None: # noqa: D107
self._semantic_manifest = semantic_manifest
self._time_spine_sources = TimeSpineSource.build_standard_time_spine_sources(semantic_manifest)
self._custom_granularities = TimeSpineSource.build_custom_granularities(list(self._time_spine_sources.values()))
self.custom_granularities = TimeSpineSource.build_custom_granularities(list(self._time_spine_sources.values()))
self._semantic_model_lookup = SemanticModelLookup(
model=semantic_manifest, custom_granularities=self._custom_granularities
model=semantic_manifest, custom_granularities=self.custom_granularities
)
self._metric_lookup = MetricLookup(
semantic_manifest=self._semantic_manifest,
semantic_model_lookup=self._semantic_model_lookup,
custom_granularities=self._custom_granularities,
custom_granularities=self.custom_granularities,
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def spec_pattern(self, input_str: str, semantic_manifest_lookup: SemanticManifes

# At this point, len(input_str_parts) >= 2
valid_granularity_names = {granularity.value for granularity in TimeGranularity}.union(
set(semantic_manifest_lookup._custom_granularities.keys())
set(semantic_manifest_lookup.custom_granularities.keys())
)
suffix = input_str_parts[-1]
time_granularity_name = suffix if suffix in valid_granularity_names else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, manifest_lookup: SemanticManifestLookup) -> None: # noqa: D1
TimeDimensionSpec.generate_possible_specs_for_time_dimension(
time_dimension_reference=TimeDimensionReference(element_name=METRIC_TIME_ELEMENT_NAME),
entity_links=(),
custom_granularities=self._manifest_lookup._custom_granularities,
custom_granularities=self._manifest_lookup.custom_granularities,
)
)

Expand Down
6 changes: 3 additions & 3 deletions metricflow/plan_conversion/dataflow_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet
),
)

def _get_time_spine_for_custom_granularity(self, custom_granularity: str) -> TimeSpineSource:
time_spine_source = self._custom_granularity_time_spine_sources.get(custom_granularity)
def _get_time_spine_for_custom_granularity(self, custom_granularity_name: str) -> TimeSpineSource:
time_spine_source = self._custom_granularity_time_spine_sources.get(custom_granularity_name)
assert time_spine_source, (
f"Custom granularity {custom_granularity} does not not exist in time spine sources. "
f"Custom granularity {custom_granularity_name} does not not exist in time spine sources. "
f"Available custom granularities: {list(self._custom_granularity_time_spine_sources.keys())}"
)
return time_spine_source
Expand Down

0 comments on commit f175b9b

Please sign in to comment.