@@ -1687,44 +1687,44 @@ def merge_multiple_snowflake_plan_expr_to_alias(
16871687 merged_dict = ExprAliasUpdateDict ()
16881688
16891689 # Collect all unique keys from all dictionaries
1690- all_keys = set ().union (* all_expr_to_alias_dicts )
1690+ all_expr_ids = set ().union (* all_expr_to_alias_dicts )
16911691
1692- conflicted_keys = {}
1692+ conflicted_expr_ids = {}
16931693
1694- for key in all_keys :
1694+ for expr_id in all_expr_ids :
16951695 values = list (
16961696 {
1697- (d [key ], d .was_updated_due_to_inheritance (key ))
1697+ (d [expr_id ], d .was_updated_due_to_inheritance (expr_id ))
16981698 for d in all_expr_to_alias_dicts
1699- if key in d
1699+ if expr_id in d
17001700 }
17011701 )
17021702 # Check if all aliases are identical
17031703 if len (values ) == 1 :
1704- merged_dict [key ] = values [0 ]
1704+ merged_dict [expr_id ] = values [0 ]
17051705 else :
1706- conflicted_keys [ key ] = values
1706+ conflicted_expr_ids [ expr_id ] = values
17071707
1708- if not conflicted_keys :
1708+ if not conflicted_expr_ids :
17091709 return merged_dict
17101710
1711- for key in conflicted_keys :
1712- candidate = set ()
1711+ for expr_id in conflicted_expr_ids :
1712+ expr_id_alias_candidates = set ()
17131713 for plan in snowflake_plans :
17141714 output_columns = []
17151715 if plan .schema_query is not None :
17161716 output_columns = [attr .name for attr in plan .output ]
17171717 tmp_alias_name , tmp_updated_due_to_inheritance = plan .expr_to_alias [
1718- key
1719- ], plan .expr_to_alias .was_updated_due_to_inheritance (key )
1718+ expr_id
1719+ ], plan .expr_to_alias .was_updated_due_to_inheritance (expr_id )
17201720 if tmp_alias_name not in output_columns or tmp_updated_due_to_inheritance :
17211721 # alias updated due to inheritance are not considered as they are not used in the output
17221722 # check Analyzer.unary_expression_extractor functions
17231723 continue
1724- if len (candidate ) == 1 :
1724+ if len (expr_id_alias_candidates ) == 1 :
17251725 # Only one candidate so far
17261726 candidate_name , candidate_updated_due_to_inheritance = next (
1727- iter (candidate )
1727+ iter (expr_id_alias_candidates )
17281728 )
17291729 if candidate_name == tmp_alias_name :
17301730 # The candidate is the same as the current alias
@@ -1734,16 +1734,18 @@ def merge_multiple_snowflake_plan_expr_to_alias(
17341734 candidate_updated_due_to_inheritance
17351735 and tmp_updated_due_to_inheritance
17361736 )
1737- candidate .pop ()
1738- candidate .add ((tmp_alias_name , tmp_updated_due_to_inheritance ))
1737+ expr_id_alias_candidates .pop ()
1738+ expr_id_alias_candidates .add (
1739+ (tmp_alias_name , tmp_updated_due_to_inheritance )
1740+ )
17391741 # Add the candidate to the merged dictionary if resolved
1740- if len (candidate ) == 1 :
1741- merged_dict [key ] = candidate .pop ()
1742+ if len (expr_id_alias_candidates ) == 1 :
1743+ merged_dict [expr_id ] = expr_id_alias_candidates .pop ()
17421744 else :
17431745 # No valid candidate found
17441746 _logger .debug (
1745- f"Expression '{ key } ' is associated with multiple aliases across different plans. "
1746- f"Unable to determine which alias to use. Conflicting values: { conflicted_keys [ key ]} "
1747+ f"Expression '{ expr_id } ' is associated with multiple aliases across different plans. "
1748+ f"Unable to determine which alias to use. Conflicting values: { conflicted_expr_ids [ expr_id ]} "
17471749 )
17481750
17491751 return merged_dict
0 commit comments