MCPcopy Create free account
hub / github.com/apache/datafusion / exclude_using_columns

Function exclude_using_columns

datafusion/expr/src/utils.rs:413–443  ·  view source on GitHub ↗

When a JOIN has a USING clause, the join columns appear in the output schema once per side (for inner/outer joins) or once total (for semi/anti joins). An unqualified wildcard should include each USING column only once. This function returns the duplicate columns that should be excluded.

(plan: &LogicalPlan)

Source from the content-addressed store, hash-verified

411/// joins). An unqualified wildcard should include each USING column only once.
412/// This function returns the duplicate columns that should be excluded.
413fn exclude_using_columns(plan: &LogicalPlan) -> Result<HashSet<Column>> {
414 let output_columns: HashSet<_> = plan.schema().columns().iter().cloned().collect();
415 let mut excluded = HashSet::new();
416 for cols in plan.using_columns()? {
417 // `using_columns()` returns join columns from both sides regardless of
418 // the join type. For semi/anti joins, only one side's columns appear in
419 // the output schema. Filter to output columns so that columns from the
420 // non-output side don't participate in the deduplication process below
421 // and displace real output columns.
422 let mut cols: Vec<_> = cols
423 .into_iter()
424 .filter(|c| output_columns.contains(c))
425 .collect();
426
427 // Sort so we keep the same qualified column, regardless of HashSet
428 // iteration order.
429 cols.sort();
430
431 // Keep only one column per name from the columns set, adding any
432 // duplicates to the excluded set.
433 let mut seen_names = HashSet::new();
434 for col in cols {
435 if seen_names.contains(col.name.as_str()) {
436 excluded.insert(col); // exclude columns with already seen name
437 } else {
438 seen_names.insert(col.name.clone()); // mark column name as seen
439 }
440 }
441 }
442 Ok(excluded)
443}
444
445/// Resolves an `Expr::Wildcard` to a collection of `Expr::Column`'s.
446pub fn expand_wildcard(

Callers 1

expand_wildcardFunction · 0.85

Calls 14

newFunction · 0.85
collectMethod · 0.80
columnsMethod · 0.80
using_columnsMethod · 0.80
clonedMethod · 0.45
iterMethod · 0.45
schemaMethod · 0.45
filterMethod · 0.45
into_iterMethod · 0.45
containsMethod · 0.45
sortMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…