Skip to content
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

Custom granularity cleanup #1430

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading