Skip to content

Commit

Permalink
Rename origin_semantic_model_reference -> semantic_model_element_refe…
Browse files Browse the repository at this point in the history
…rence
  • Loading branch information
courtneyholcomb committed Apr 23, 2024
1 parent e1a2bda commit c36a3d5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions metricflow/dataflow/builder/node_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs(
if entity_instance_in_right_node is None:
raise RuntimeError(f"Could not find entity instance with name ({entity_spec_in_right_node})")

element_reference = entity_instance_in_right_node.checked_origin_semantic_model_reference
element_reference = entity_instance_in_right_node.checked_semantic_model_element_reference
entity_in_right_node = self._semantic_model_lookup.get_entity_in_semantic_model(element_reference)
if entity_in_right_node is None:
raise RuntimeError(f"Invalid SemanticModelElementReference {element_reference}")
Expand All @@ -249,8 +249,8 @@ def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs(
continue

if not self._join_evaluator.is_valid_semantic_model_join(
left_semantic_model_reference=entity_instance_in_left_node.checked_origin_semantic_model_reference.semantic_model_reference,
right_semantic_model_reference=entity_instance_in_right_node.checked_origin_semantic_model_reference.semantic_model_reference,
left_semantic_model_reference=entity_instance_in_left_node.checked_semantic_model_element_reference.semantic_model_reference,
right_semantic_model_reference=entity_instance_in_right_node.checked_semantic_model_element_reference.semantic_model_reference,
on_entity_reference=entity_spec_in_right_node.reference,
):
# If joining to ComputeMetricsNode, the right node is pre-aggregated.
Expand Down
8 changes: 4 additions & 4 deletions metricflow/dataset/convert_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _create_dimension_instance(
return DimensionInstance(
associated_columns=(self._column_association_resolver.resolve_spec(dimension_spec),),
spec=dimension_spec,
origin_semantic_model_reference=SemanticModelElementReference(
semantic_model_element_reference=SemanticModelElementReference(
semantic_model_name=semantic_model_name,
element_name=dimension.reference.element_name,
),
Expand All @@ -120,7 +120,7 @@ def _create_time_dimension_instance(
return TimeDimensionInstance(
associated_columns=(self._column_association_resolver.resolve_spec(time_dimension_spec),),
spec=time_dimension_spec,
origin_semantic_model_reference=(
semantic_model_element_reference=(
SemanticModelElementReference(semantic_model_name=semantic_model_name, element_name=element_name)
if semantic_model_name
else None
Expand All @@ -141,7 +141,7 @@ def _create_entity_instance(
return EntityInstance(
associated_columns=(self._column_association_resolver.resolve_spec(entity_spec),),
spec=entity_spec,
origin_semantic_model_reference=SemanticModelElementReference(
semantic_model_element_reference=SemanticModelElementReference(
semantic_model_name=semantic_model_name, element_name=entity.reference.element_name
),
)
Expand Down Expand Up @@ -188,7 +188,7 @@ def _convert_measures(
measure_instance = MeasureInstance(
associated_columns=(self._column_association_resolver.resolve_spec(measure_spec),),
spec=measure_spec,
origin_semantic_model_reference=SemanticModelElementReference(
semantic_model_element_reference=SemanticModelElementReference(
semantic_model_name=semantic_model_name, element_name=measure.reference.element_name
),
aggregation_state=AggregationState.NON_AGGREGATED,
Expand Down
12 changes: 6 additions & 6 deletions metricflow/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def associated_column(self) -> ColumnAssociation:

@dataclass(frozen=True)
class SemanticModelElementInstance(SerializableDataclass): # noqa: D101
origin_semantic_model_reference: Optional[SemanticModelElementReference]
semantic_model_element_reference: Optional[SemanticModelElementReference]

@property
def checked_origin_semantic_model_reference(self) -> SemanticModelElementReference:
"""Get origin_semantic_model_reference, error if it doesn't exist.
def checked_semantic_model_element_reference(self) -> SemanticModelElementReference:
"""Get semantic_model_element_reference, error if it doesn't exist.
Mostly used for type-checking simplification.
"""
if self.origin_semantic_model_reference is None:
if self.semantic_model_element_reference is None:
raise ValueError(
f"Expected origin_semantic_model_reference for SemanticModelElementInstance, but found none. Instance: {self}"
f"Expected semantic_model_element_reference for SemanticModelElementInstance, but found none. Instance: {self}"
)
return self.origin_semantic_model_reference
return self.semantic_model_element_reference


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _semantic_model_of_entity_in_instance_set(
f"Not exactly 1 matching entity instances found: {matching_entity_instances} for {entity_reference} in "
f"{mf_pformat(instance_set)}"
)
return matching_entity_instances[0].checked_origin_semantic_model_reference.semantic_model_reference
return matching_entity_instances[0].checked_semantic_model_element_reference.semantic_model_reference

def is_valid_instance_set_join(
self,
Expand Down
10 changes: 5 additions & 5 deletions metricflow/plan_conversion/dataflow_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _make_time_spine_data_set(
day.
"""
time_spine_instance = TimeDimensionInstance(
origin_semantic_model_reference=agg_time_dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=agg_time_dimension_instance.semantic_model_element_reference,
associated_columns=(
ColumnAssociation(
column_name=agg_time_dimension_column_name,
Expand Down Expand Up @@ -1077,11 +1077,11 @@ def visit_metric_time_dimension_transform_node(self, node: MetricTimeDimensionTr
output_measure_instances = []
for measure_instance in input_data_set.instance_set.measure_instances:
semantic_model = self._semantic_model_lookup.get_by_reference(
semantic_model_reference=measure_instance.checked_origin_semantic_model_reference.semantic_model_reference
semantic_model_reference=measure_instance.checked_semantic_model_element_reference.semantic_model_reference
)
assert semantic_model is not None, (
f"{measure_instance} was defined from "
f"{measure_instance.checked_origin_semantic_model_reference.semantic_model_reference}, but that can't be found"
f"{measure_instance.checked_semantic_model_element_reference.semantic_model_reference}, but that can't be found"
)
aggregation_time_dimension_for_measure = semantic_model.checked_agg_time_dimension_for_measure(
measure_reference=measure_instance.spec.reference
Expand Down Expand Up @@ -1114,7 +1114,7 @@ def visit_metric_time_dimension_transform_node(self, node: MetricTimeDimensionTr
)
output_time_dimension_instances.append(
TimeDimensionInstance(
origin_semantic_model_reference=matching_time_dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=matching_time_dimension_instance.semantic_model_element_reference,
associated_columns=(self._column_association_resolver.resolve_spec(metric_time_dimension_spec),),
spec=metric_time_dimension_spec,
)
Expand Down Expand Up @@ -1430,7 +1430,7 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet
aggregation_state=original_time_spine_dim_instance.spec.aggregation_state,
)
time_spine_dim_instance = TimeDimensionInstance(
origin_semantic_model_reference=original_time_spine_dim_instance.origin_semantic_model_reference,
semantic_model_element_reference=original_time_spine_dim_instance.semantic_model_element_reference,
associated_columns=(self._column_association_resolver.resolve_spec(time_dim_spec),),
spec=time_dim_spec,
)
Expand Down
22 changes: 11 additions & 11 deletions metricflow/plan_conversion/instance_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def transform(self, instance_set: InstanceSet) -> Optional[ValidityWindowJoinDes
semantic_model_to_window: Dict[SemanticModelReference, ValidityWindowJoinDescription] = {}
instances_by_semantic_model = bucket(
instance_set.time_dimension_instances,
lambda x: x.checked_origin_semantic_model_reference.semantic_model_reference,
lambda x: x.checked_semantic_model_element_reference.semantic_model_reference,
)
for semantic_model_reference in instances_by_semantic_model:
validity_dims = self._get_validity_window_dimensions_for_semantic_model(semantic_model_reference)
Expand Down Expand Up @@ -410,7 +410,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
dimension_instances_with_additional_link.append(
DimensionInstance(
associated_columns=dimension_instance.associated_columns,
origin_semantic_model_reference=dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=dimension_instance.semantic_model_element_reference,
spec=transformed_dimension_spec_from_right,
)
)
Expand All @@ -431,7 +431,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
time_dimension_instances_with_additional_link.append(
TimeDimensionInstance(
associated_columns=time_dimension_instance.associated_columns,
origin_semantic_model_reference=time_dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=time_dimension_instance.semantic_model_element_reference,
spec=transformed_time_dimension_spec_from_right,
)
)
Expand All @@ -451,7 +451,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
entity_instances_with_additional_link.append(
EntityInstance(
associated_columns=entity_instance.associated_columns,
origin_semantic_model_reference=entity_instance.origin_semantic_model_reference,
semantic_model_element_reference=entity_instance.semantic_model_element_reference,
spec=transformed_entity_spec_from_right,
)
)
Expand Down Expand Up @@ -613,7 +613,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
measure_instances = tuple(
MeasureInstance(
associated_columns=x.associated_columns,
origin_semantic_model_reference=x.origin_semantic_model_reference,
semantic_model_element_reference=x.semantic_model_element_reference,
aggregation_state=self._aggregation_state_changes[x.aggregation_state],
spec=x.spec,
)
Expand Down Expand Up @@ -654,7 +654,7 @@ def _update_fill_nulls_with(self, measure_instances: Tuple[MeasureInstance, ...]
associated_columns=instance.associated_columns,
spec=measure_spec,
aggregation_state=instance.aggregation_state,
origin_semantic_model_reference=instance.origin_semantic_model_reference,
semantic_model_element_reference=instance.semantic_model_element_reference,
)
)

Expand Down Expand Up @@ -709,7 +709,7 @@ def _alias_measure_instances(self, measure_instances: Tuple[MeasureInstance, ...
associated_columns=instance.associated_columns,
spec=measure_spec,
aggregation_state=instance.aggregation_state,
origin_semantic_model_reference=instance.origin_semantic_model_reference,
semantic_model_element_reference=instance.semantic_model_element_reference,
)
)

Expand Down Expand Up @@ -942,7 +942,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
MeasureInstance(
associated_columns=(self._column_association_resolver.resolve_spec(input_measure_instance.spec),),
spec=input_measure_instance.spec,
origin_semantic_model_reference=input_measure_instance.origin_semantic_model_reference,
semantic_model_element_reference=input_measure_instance.semantic_model_element_reference,
aggregation_state=input_measure_instance.aggregation_state,
)
)
Expand All @@ -953,7 +953,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
DimensionInstance(
associated_columns=(self._column_association_resolver.resolve_spec(input_dimension_instance.spec),),
spec=input_dimension_instance.spec,
origin_semantic_model_reference=input_dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=input_dimension_instance.semantic_model_element_reference,
)
)

Expand All @@ -965,7 +965,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
self._column_association_resolver.resolve_spec(input_time_dimension_instance.spec),
),
spec=input_time_dimension_instance.spec,
origin_semantic_model_reference=input_time_dimension_instance.origin_semantic_model_reference,
semantic_model_element_reference=input_time_dimension_instance.semantic_model_element_reference,
)
)

Expand All @@ -975,7 +975,7 @@ def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
EntityInstance(
associated_columns=(self._column_association_resolver.resolve_spec(input_entity_instance.spec),),
spec=input_entity_instance.spec,
origin_semantic_model_reference=input_entity_instance.origin_semantic_model_reference,
semantic_model_element_reference=input_entity_instance.semantic_model_element_reference,
)
)

Expand Down
2 changes: 1 addition & 1 deletion metricflow/plan_conversion/node_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _node_contains_entity(
if len(entity_spec_in_first_node.entity_links) > 0:
continue

element_reference = entity_instance_in_first_node.checked_origin_semantic_model_reference
element_reference = entity_instance_in_first_node.checked_semantic_model_element_reference
entity = self._semantic_model_lookup.get_entity_in_semantic_model(element_reference)
if entity is None:
raise RuntimeError(f"Invalid SemanticModelElementReference {element_reference}")
Expand Down
2 changes: 1 addition & 1 deletion tests/dataflow/builder/test_node_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_no_parent_node_data_set(
column_name="bookings", single_column_correlation_key=SingleColumnCorrelationKey()
),
),
origin_semantic_model_reference=SemanticModelElementReference(
semantic_model_element_reference=SemanticModelElementReference(
semantic_model_name="fct_bookings_semantic_model", element_name="bookings"
),
spec=MeasureSpec(
Expand Down

0 comments on commit c36a3d5

Please sign in to comment.