-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make source_semantic_models property accessible from a DataflowPlanNo…
…de (#1218) This change ultimately adds the source_semantic_models property to the DataflowPlan and adds a hook for enabling access to it from any arbitrary DataflowPlanNode. We currently have two use-cases for this, one in the cloud codebase that needs the semantic model inputs for a dataflow plan, and the upcoming predicate pushdown evaluation which needs the semantic model inputs for a given DataflowPlanNode. An earlier version of this change added the property directly to the DataflowPlanNode, which would satisfy both use cases above. The issue with having this property assigned directly to a DataflowPlanNode is that the property might be considered both a node-level and graph-level attribute, so it's not clear where to put the accessor. The solution we came up with for this was to allow access to a DataflowPlan DAG object built from the node, which would effectively encapsulate the subgraph represented by the node and its ancestors. Then we can access these subgraph properties through the DataflowPlan while making it clear to the caller that what they are asking for is a subgraph-level, rather than a node-level attribute.
- Loading branch information
Showing
5 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Make source semantic models available from DataflowPlanNode instances | ||
time: 2024-05-16T14:46:03.707367-07:00 | ||
custom: | ||
Author: tlento | ||
Issue: "1218" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Tests for operations on dataflow plans and dataflow plan nodes.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dbt_semantic_interfaces.references import EntityReference, SemanticModelReference | ||
from metricflow_semantics.specs.query_spec import MetricFlowQuerySpec | ||
from metricflow_semantics.specs.spec_classes import ( | ||
DimensionSpec, | ||
MetricSpec, | ||
) | ||
|
||
from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder | ||
|
||
|
||
def test_source_semantic_models_accessor( | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
) -> None: | ||
"""Tests source semantic models access for a simple query plan.""" | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings"),), | ||
) | ||
) | ||
|
||
assert dataflow_plan.source_semantic_models == frozenset( | ||
[SemanticModelReference(semantic_model_name="bookings_source")] | ||
) | ||
|
||
|
||
def test_multi_hop_joined_source_semantic_models_accessor( | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
) -> None: | ||
"""Tests source semantic models access for a multi-hop join plan.""" | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings"),), | ||
dimension_specs=( | ||
DimensionSpec( | ||
element_name="home_state_latest", | ||
entity_links=( | ||
EntityReference(element_name="listing"), | ||
EntityReference(element_name="user"), | ||
), | ||
), | ||
), | ||
) | ||
) | ||
|
||
assert dataflow_plan.source_semantic_models == frozenset( | ||
[ | ||
SemanticModelReference(semantic_model_name="bookings_source"), | ||
SemanticModelReference(semantic_model_name="listings_latest"), | ||
SemanticModelReference(semantic_model_name="users_latest"), | ||
] | ||
) |