From 271995418655e76a188566b90608519537c49bf7 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Wed, 18 Dec 2024 13:34:50 -0800 Subject: [PATCH] fixup! Build DataflowPlan for custom offset window with most grains --- .../dataflow/builder/dataflow_plan_builder.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index f66667cbf..e1ab7f188 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -671,11 +671,7 @@ def _build_derived_metric_output_node( requested_agg_time_dimension_specs=queried_agg_time_dimension_specs, join_on_time_dimension_spec=self._sort_by_base_granularity(queried_agg_time_dimension_specs)[0], offset_window=( - metric_spec.offset_window - if metric_spec.offset_window - and metric_spec.offset_window.granularity - not in self._semantic_model_lookup.custom_granularity_names - else None + metric_spec.offset_window if not self._offset_window_is_custom(metric_spec.offset_window) else None ), offset_to_grain=metric_spec.offset_to_grain, join_type=SqlJoinType.INNER, @@ -1674,9 +1670,7 @@ def _build_aggregated_measure_from_measure_source_node( join_on_time_dimension_spec=join_on_time_dimension_spec, offset_window=( before_aggregation_time_spine_join_description.offset_window - if before_aggregation_time_spine_join_description.offset_window - and before_aggregation_time_spine_join_description.offset_window.granularity - not in self._semantic_model_lookup.custom_granularity_names + if not self._offset_window_is_custom(before_aggregation_time_spine_join_description.offset_window) else None ), offset_to_grain=before_aggregation_time_spine_join_description.offset_to_grain, @@ -1895,7 +1889,7 @@ def _build_time_spine_node( required_time_spine_specs = required_time_spine_spec_set.time_dimension_specs should_dedupe = False - if offset_window and offset_window.granularity in self._semantic_model_lookup._custom_granularities: + if offset_window and self._offset_window_is_custom(offset_window): time_spine_node = self._build_custom_offset_time_spine_node( offset_window=offset_window, required_time_spine_specs=required_time_spine_specs ) @@ -2000,3 +1994,9 @@ def _determine_time_spine_join_spec( time_granularity=join_spec_grain, date_part=None ) return join_on_time_dimension_spec + + def _offset_window_is_custom(self, offset_window: Optional[MetricTimeWindow]) -> bool: + return ( + offset_window is not None + and offset_window.granularity in self._semantic_model_lookup.custom_granularity_names + )