Skip to content

Commit 8f9a111

Browse files
committed
change to count occurrences of each name
1 parent d14f7a4 commit 8f9a111

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

  • datafusion/expr/src/logical_plan

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,20 +2413,17 @@ impl SubqueryAlias {
24132413
// duplicates to keep the Arrow schema free of duplicates, but we still
24142414
// need to reject unqualified references to those names from outer
24152415
// queries.
2416-
let ambiguous_names: HashSet<String> = aliases
2417-
.iter()
2418-
.zip(plan.schema().fields().iter())
2419-
.filter_map(|(alias, field)| {
2420-
// When a field was given a rename alias it means its original
2421-
// name already appeared in the schema → the original name is
2422-
// ambiguous.
2423-
if alias.is_some() {
2424-
Some(field.name().to_string())
2425-
} else {
2426-
None
2427-
}
2428-
})
2429-
.collect();
2416+
let ambiguous_names: HashSet<String> = {
2417+
let mut name_counts: HashMap<&str, usize> = HashMap::new();
2418+
for field in plan.schema().fields() {
2419+
*name_counts.entry(field.name().as_str()).or_insert(0) += 1;
2420+
}
2421+
name_counts
2422+
.into_iter()
2423+
.filter(|&(_, count)| count >= 2)
2424+
.map(|(name, _)| name.to_string())
2425+
.collect()
2426+
};
24302427

24312428
// Insert a projection node, if needed, to make sure aliases are applied.
24322429
let plan = if is_projection_needed {

0 commit comments

Comments
 (0)