Skip to content

Commit

Permalink
Remove bad granularity assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 27, 2024
1 parent 088c68b commit 9186221
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def without_first_entity_link(self) -> TimeDimensionSpec: # noqa: D102

@property
def without_entity_links(self) -> TimeDimensionSpec: # noqa: D102
return TimeDimensionSpec.from_name(self.element_name)
return TimeDimensionSpec(
element_name=self.element_name,
time_granularity=self.time_granularity,
date_part=self.date_part,
entity_links=(),
)

@staticmethod
def from_name(name: str) -> TimeDimensionSpec: # noqa: D102
Expand Down
11 changes: 7 additions & 4 deletions metricflow/dataflow/builder/node_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,26 @@ def _find_joinable_candidate_nodes_that_can_satisfy_linkable_specs(
candidates_for_join: List[JoinLinkableInstancesRecipe] = []
left_node_spec_set = left_node_instance_set.spec_set
for right_node in self._nodes_available_for_joins:
data_set_in_right_node: SqlDataSet = self._node_data_set_resolver.get_output_data_set(right_node)
linkable_specs_in_right_node = data_set_in_right_node.instance_set.spec_set.linkable_specs

# If right node is time spine source node, use cross join.
if right_node in self._time_spine_nodes:
needed_metric_time_specs = group_specs_by_type(needed_linkable_specs).metric_time_specs
satisfiable_metric_time_specs = set(needed_linkable_specs).intersection(
set(linkable_specs_in_right_node)
)
candidates_for_join.append(
JoinLinkableInstancesRecipe(
node_to_join=right_node,
join_on_entity=None,
satisfiable_linkable_specs=list(needed_metric_time_specs),
satisfiable_linkable_specs=list(satisfiable_metric_time_specs),
join_on_partition_dimensions=(),
join_on_partition_time_dimensions=(),
join_type=SqlJoinType.CROSS_JOIN,
)
)
continue

data_set_in_right_node: SqlDataSet = self._node_data_set_resolver.get_output_data_set(right_node)
linkable_specs_in_right_node = data_set_in_right_node.instance_set.spec_set.linkable_specs
entity_specs_in_right_node = data_set_in_right_node.instance_set.spec_set.entity_specs

# For each unlinked entity in the data set, create a candidate for joining.
Expand Down
4 changes: 2 additions & 2 deletions metricflow/dataset/convert_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _create_time_dimension_instance(
self,
element_name: str,
entity_links: Tuple[EntityReference, ...],
time_granularity: TimeGranularity = DEFAULT_TIME_GRANULARITY,
time_granularity: TimeGranularity,
date_part: Optional[DatePart] = None,
semantic_model_name: Optional[str] = None,
) -> TimeDimensionInstance:
Expand Down Expand Up @@ -332,7 +332,7 @@ def _build_time_dimension_instances_and_columns(
) -> Tuple[List[TimeDimensionInstance], List[SqlSelectColumn]]:
time_dimension_instances: List[TimeDimensionInstance] = []
select_columns: List[SqlSelectColumn] = []
# Add time dimensions with a smaller granularity for ease in query resolution
# Add time dimensions with a larger granularity for ease in query resolution
for time_granularity in TimeGranularity:
if time_granularity.to_int() > defined_time_granularity.to_int():
time_dimension_instance = self._create_time_dimension_instance(
Expand Down

0 comments on commit 9186221

Please sign in to comment.