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)
| 411 | /// joins). An unqualified wildcard should include each USING column only once. |
| 412 | /// This function returns the duplicate columns that should be excluded. |
| 413 | fn 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. |
| 446 | pub fn expand_wildcard( |
no test coverage detected
searching dependent graphs…