Skip to content

Commit

Permalink
Update related metric_time documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 12, 2024
1 parent f642346 commit 6467c8d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions metricflow-semantics/metricflow_semantics/query/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def _get_saved_query(self, saved_query_parameter: SavedQueryParameter) -> SavedQ
return matching_saved_queries[0]

@staticmethod
def _metric_time_granularity(time_dimension_specs: Sequence[TimeDimensionSpec]) -> Optional[TimeGranularity]:
def _get_smallest_requested_metric_time_granularity(
time_dimension_specs: Sequence[TimeDimensionSpec],
) -> Optional[TimeGranularity]:
matching_specs: Sequence[InstanceSpec] = time_dimension_specs

for pattern_to_apply in (
Expand All @@ -174,18 +176,21 @@ def _adjust_time_constraint(
time_dimension_specs_in_query: Sequence[TimeDimensionSpec],
time_constraint: TimeRangeConstraint,
) -> TimeRangeConstraint:
metric_time_granularity = MetricFlowQueryParser._metric_time_granularity(time_dimension_specs_in_query)
"""Change the time range so that the ends are at the ends of the requested time granularity windows.
e.g. [2020-01-15, 2020-2-15] with MONTH granularity -> [2020-01-01, 2020-02-29]
"""
metric_time_granularity = MetricFlowQueryParser._get_smallest_requested_metric_time_granularity(
time_dimension_specs_in_query
)
if metric_time_granularity is None:
# This indicates there were no metric time specs in the query, so use smallest available granularity for metric_time.
group_by_item_resolver = GroupByItemResolver(
manifest_lookup=self._manifest_lookup,
resolution_dag=resolution_dag,
)
metric_time_granularity = group_by_item_resolver.resolve_min_metric_time_grain()

"""Change the time range so that the ends are at the ends of the appropriate time granularity windows.
e.g. [2020-01-15, 2020-2-15] with MONTH granularity -> [2020-01-01, 2020-02-29]
"""
return self._time_period_adjuster.expand_time_constraint_to_fill_granularity(
time_constraint=time_constraint,
granularity=metric_time_granularity,
Expand Down

0 comments on commit 6467c8d

Please sign in to comment.