(
env: &mut Environment,
all_rows: &mut Vec<Row>,
joins: &Vec<Join>,
tables_selections: &Vec<TableSelection>,
selected_rows_per_table: &mut HashMap<String, Vec<Row>>,
hidden_se
| 14 | |
| 15 | #[inline(always)] |
| 16 | pub(crate) fn apply_join_operation( |
| 17 | env: &mut Environment, |
| 18 | all_rows: &mut Vec<Row>, |
| 19 | joins: &Vec<Join>, |
| 20 | tables_selections: &Vec<TableSelection>, |
| 21 | selected_rows_per_table: &mut HashMap<String, Vec<Row>>, |
| 22 | hidden_selection_per_table: &HashMap<String, usize>, |
| 23 | titles: &[String], |
| 24 | ) -> Result<(), String> { |
| 25 | // If no join, just merge them, can be optimized to append only the first value in the map |
| 26 | if joins.is_empty() { |
| 27 | for table_selection in tables_selections { |
| 28 | let table_rows = selected_rows_per_table |
| 29 | .get_mut(&table_selection.table_name) |
| 30 | .unwrap(); |
| 31 | all_rows.append(table_rows); |
| 32 | } |
| 33 | return Ok(()); |
| 34 | } |
| 35 | |
| 36 | let mut current_tables_rows: Vec<Row> = vec![]; |
| 37 | let mut all_rows_hidden_count = 0; |
| 38 | |
| 39 | // Apply join operator depend on the join type |
| 40 | for join in joins { |
| 41 | let mut current_join_rows: Vec<Row> = vec![]; |
| 42 | |
| 43 | let left_rows: &Vec<Row>; |
| 44 | let left_hidden_count: usize; |
| 45 | |
| 46 | let right_rows: &Vec<Row>; |
| 47 | let right_hidden_count: usize; |
| 48 | |
| 49 | match &join.operand { |
| 50 | JoinOperand::OuterAndInner(outer, inner) => { |
| 51 | left_hidden_count = *hidden_selection_per_table.get(outer).unwrap_or(&0); |
| 52 | right_hidden_count = *hidden_selection_per_table.get(inner).unwrap_or(&0); |
| 53 | all_rows_hidden_count += left_hidden_count + right_hidden_count; |
| 54 | |
| 55 | left_rows = selected_rows_per_table.get(outer).unwrap(); |
| 56 | right_rows = selected_rows_per_table.get(inner).unwrap(); |
| 57 | } |
| 58 | |
| 59 | JoinOperand::Inner(inner) => { |
| 60 | left_hidden_count = all_rows_hidden_count; |
| 61 | right_hidden_count = *hidden_selection_per_table.get(inner).unwrap_or(&0); |
| 62 | all_rows_hidden_count += right_hidden_count; |
| 63 | |
| 64 | left_rows = ¤t_tables_rows; |
| 65 | right_rows = selected_rows_per_table.get(inner).unwrap(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Don't apply CROSS JOIN if left or right rows are empty |
| 70 | if join.kind == JoinKind::Cross && (left_rows.is_empty() || right_rows.is_empty()) { |
| 71 | continue; |
| 72 | } |
| 73 |
no test coverage detected
searching dependent graphs…