Skip to content

Commit

Permalink
Make TimeDimensionSpec.with_base_grain() a function instead of a prop…
Browse files Browse the repository at this point in the history
…erty
  • Loading branch information
courtneyholcomb committed Sep 24, 2024
1 parent 85f96c1 commit d5e14d2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def with_grain(self, time_granularity: ExpandedTimeGranularity) -> TimeDimension
aggregation_state=self.aggregation_state,
)

@property
def with_base_grain(self) -> TimeDimensionSpec: # noqa: D102
return TimeDimensionSpec(
element_name=self.element_name,
Expand Down
8 changes: 6 additions & 2 deletions metricflow/dataflow/builder/dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,9 @@ def _build_plan_for_distinct_values(

for time_dimension_spec in required_linkable_specs.time_dimension_specs:
if time_dimension_spec.time_granularity.is_custom_granularity:
include_base_grain = time_dimension_spec.with_base_grain in required_linkable_specs.time_dimension_specs
include_base_grain = (
time_dimension_spec.with_base_grain() in required_linkable_specs.time_dimension_specs
)
output_node = JoinToCustomGranularityNode.create(
parent_node=output_node,
time_dimension_spec=time_dimension_spec,
Expand Down Expand Up @@ -1572,7 +1574,9 @@ def _build_aggregated_measure_from_measure_source_node(

for time_dimension_spec in queried_linkable_specs.time_dimension_specs:
if time_dimension_spec.time_granularity.is_custom_granularity:
include_base_grain = time_dimension_spec.with_base_grain in required_linkable_specs.time_dimension_specs
include_base_grain = (
time_dimension_spec.with_base_grain() in required_linkable_specs.time_dimension_specs
)
unaggregated_measure_node = JoinToCustomGranularityNode.create(
parent_node=unaggregated_measure_node,
time_dimension_spec=time_dimension_spec,
Expand Down
2 changes: 1 addition & 1 deletion metricflow/dataflow/builder/node_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def evaluate_node(
data_set_linkable_specs = candidate_spec_set.linkable_specs
# Look for which nodes can satisfy the linkable specs at their base grains. Custom grains will be joined later.
required_linkable_specs_with_base_grains = [
spec.with_base_grain if isinstance(spec, TimeDimensionSpec) else spec for spec in required_linkable_specs
spec.with_base_grain() if isinstance(spec, TimeDimensionSpec) else spec for spec in required_linkable_specs
]

# These are linkable specs in the start node data set. Those are considered "local".
Expand Down
2 changes: 1 addition & 1 deletion metricflow/plan_conversion/dataflow_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNod
parent_alias = parent_data_set.checked_sql_select_node.from_source_alias
parent_time_dimension_instance: Optional[TimeDimensionInstance] = None
for instance in parent_data_set.instance_set.time_dimension_instances:
if instance.spec == node.time_dimension_spec.with_base_grain:
if instance.spec == node.time_dimension_spec.with_base_grain():
parent_time_dimension_instance = instance
break
assert parent_time_dimension_instance, (
Expand Down

0 comments on commit d5e14d2

Please sign in to comment.