Skip to content

Commit

Permalink
Bug fix: prioritize nodees based on evaluation cost
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Oct 10, 2023
1 parent e5e980c commit d06eefb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions metricflow/dataflow/builder/dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,17 @@ def _find_measure_recipe(
logger.info(f"Found {len(node_to_evaluation)} candidate measure nodes.")

if len(node_to_evaluation) > 0:
cost_function = DefaultCostFunction()

node_with_lowest_cost = min(node_to_evaluation, key=cost_function.calculate_cost)
evaluation = node_to_evaluation[node_with_lowest_cost]
# All source nodes cost 0. Get evaluation with lowest cost.
node_with_lowest_evaluation_cost = min(
node_to_evaluation, key=lambda x: len(node_to_evaluation[x].join_recipes)
)
evaluation = node_to_evaluation[node_with_lowest_evaluation_cost]
logger.info(
"Lowest cost node is:\n"
+ pformat_big_objects(
lowest_cost_node=dataflow_dag_as_text(node_with_lowest_cost),
lowest_cost_node=dataflow_dag_as_text(node_with_lowest_evaluation_cost),
evaluation=evaluation,
cost=cost_function.calculate_cost(node_with_lowest_cost),
joins=len(node_to_evaluation[node_with_lowest_evaluation_cost].join_recipes),
)
)

Expand All @@ -585,14 +586,14 @@ def _find_measure_recipe(
)

return MeasureRecipe(
measure_node=node_with_lowest_cost,
measure_node=node_with_lowest_evaluation_cost,
required_local_linkable_specs=(
evaluation.local_linkable_specs
+ required_local_entity_specs
+ required_local_dimension_specs
+ required_local_time_dimension_specs
),
join_linkable_instances_recipes=node_to_evaluation[node_with_lowest_cost].join_recipes,
join_linkable_instances_recipes=node_to_evaluation[node_with_lowest_evaluation_cost].join_recipes,
)

logger.error("No recipe could be constructed.")
Expand Down

0 comments on commit d06eefb

Please sign in to comment.