Find columns that appear in all termsets
(
termsets: &[Vec<ColOpLitOrInList<'a>>],
)
| 503 | |
| 504 | /// Find columns that appear in all termsets |
| 505 | fn 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)] |
| 535 | mod test { |
no test coverage detected
searching dependent graphs…