Skip to content

Commit 47bc9f2

Browse files
committed
Update to convert metric nodes to cte.
1 parent dadb857 commit 47bc9f2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

metricflow/dataflow/dataflow_plan_analyzer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def find_common_branches(dataflow_plan: DataflowPlan) -> Sequence[DataflowPlanNo
4141

4242
@staticmethod
4343
def group_nodes_by_type(dataflow_plan: DataflowPlan) -> DataflowPlanNodeSet:
44-
"""Grouops dataflow plan nodes by type."""
44+
"""Groups dataflow plan nodes by type."""
4545
grouping_visitor = _GroupNodesByTypeVisitor()
4646
return dataflow_plan.sink_node.accept(grouping_visitor)
4747

@@ -98,12 +98,14 @@ class DataflowPlanNodeSet(Mergeable):
9898

9999
compute_metric_nodes: FrozenSet[ComputeMetricsNode]
100100

101+
@override
101102
def merge(self, other: DataflowPlanNodeSet) -> DataflowPlanNodeSet:
102103
return DataflowPlanNodeSet(
103104
compute_metric_nodes=self.compute_metric_nodes.union(other.compute_metric_nodes),
104105
)
105106

106107
@classmethod
108+
@override
107109
def empty_instance(cls) -> DataflowPlanNodeSet:
108110
return DataflowPlanNodeSet(
109111
compute_metric_nodes=frozenset(),

metricflow/plan_conversion/dataflow_to_sql.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ def _get_nodes_to_convert_to_cte(
273273
"""Handles logic for selecting which nodes to convert to CTEs based on the request."""
274274
dataflow_plan = dataflow_plan_node.as_plan()
275275
nodes_to_convert_to_cte: Set[DataflowPlanNode] = set(DataflowPlanAnalyzer.find_common_branches(dataflow_plan))
276-
# Additional nodes will be added later.
276+
277+
compute_metric_nodes = DataflowPlanAnalyzer.group_nodes_by_type(dataflow_plan).compute_metric_nodes
278+
if len(compute_metric_nodes) > 1:
279+
nodes_to_convert_to_cte.update(compute_metric_nodes)
277280

278281
return frozenset(nodes_to_convert_to_cte)
279282

0 commit comments

Comments
 (0)