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

Function find_common_columns

datafusion/physical-expr/src/utils/guarantee.rs:505–532  ·  view source on GitHub ↗

Find columns that appear in all termsets

(
    termsets: &[Vec<ColOpLitOrInList<'a>>],
)

Source from the content-addressed store, hash-verified

503
504/// Find columns that appear in all termsets
505fn find_common_columns<'a>(
506 termsets: &[Vec<ColOpLitOrInList<'a>>],
507) -> Vec<&'a crate::expressions::Column> {
508 if termsets.is_empty() {
509 return Vec::new();
510 }
511
512 // Start with columns from the first termset
513 let mut common_cols: HashSet<_> = termsets[0].iter().map(|term| term.col()).collect();
514
515 // check if any common_col in one termset occur many times
516 // e.g. (a = 1 AND a = 2) OR (a = 2 AND b = 3), should not infer a guarantee
517 // TODO: for above case, we can infer a IN (2) AND b IN (3)
518 if common_cols.len() != termsets[0].len() {
519 return Vec::new();
520 }
521
522 // Intersect with columns from remaining termsets
523 for termset in termsets.iter().skip(1) {
524 let termset_cols: HashSet<_> = termset.iter().map(|term| term.col()).collect();
525 if termset_cols.len() != termset.len() {
526 return Vec::new();
527 }
528 common_cols = common_cols.intersection(&termset_cols).cloned().collect();
529 }
530
531 common_cols.into_iter().collect()
532}
533
534#[cfg(test)]
535mod test {

Callers 1

analyzeMethod · 0.85

Calls 10

newFunction · 0.85
collectMethod · 0.80
colMethod · 0.80
is_emptyMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
skipMethod · 0.45
clonedMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…