Fuses multiple `Join` operators into one `Join` operator. Return Ok(true) iff the action manipulated the tree after detecting the most general pattern.
(relation: &mut MirRelationExpr)
| 87 | /// Return Ok(true) iff the action manipulated the tree after detecting the |
| 88 | /// most general pattern. |
| 89 | pub fn action(relation: &mut MirRelationExpr) -> Result<bool, TransformError> { |
| 90 | if let MirRelationExpr::Join { |
| 91 | inputs, |
| 92 | equivalences, |
| 93 | .. |
| 94 | } = relation |
| 95 | { |
| 96 | // Local non-fusion tidying. |
| 97 | inputs.retain(|e| !e.is_constant_singleton()); |
| 98 | if inputs.len() == 0 { |
| 99 | *relation = MirRelationExpr::constant(vec![vec![]], ReprRelationType::empty()) |
| 100 | .filter(unpack_equivalences(equivalences)); |
| 101 | return Ok(false); |
| 102 | } |
| 103 | if inputs.len() == 1 { |
| 104 | *relation = inputs |
| 105 | .pop() |
| 106 | .unwrap() |
| 107 | .filter(unpack_equivalences(equivalences)); |
| 108 | return Ok(false); |
| 109 | } |
| 110 | |
| 111 | // Bail early if no children are MFPs around a Join |
| 112 | if inputs.iter().any(|mut expr| { |
| 113 | let mut result = None; |
| 114 | while result.is_none() { |
| 115 | match expr { |
| 116 | MirRelationExpr::Map { input, .. } |
| 117 | | MirRelationExpr::Filter { input, .. } |
| 118 | | MirRelationExpr::Project { input, .. } => { |
| 119 | expr = &**input; |
| 120 | } |
| 121 | MirRelationExpr::Join { .. } => { |
| 122 | result = Some(true); |
| 123 | } |
| 124 | _ => { |
| 125 | result = Some(false); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | result.unwrap() |
| 130 | }) { |
| 131 | // Each input is either an MFP around a Join, or just an expression. |
| 132 | let children = inputs |
| 133 | .iter() |
| 134 | .map(|expr| { |
| 135 | let (mfp, inner) = MapFilterProject::extract_from_expression(expr); |
| 136 | if let MirRelationExpr::Join { |
| 137 | inputs, |
| 138 | equivalences, |
| 139 | .. |
| 140 | } = inner |
| 141 | { |
| 142 | Ok((mfp, (inputs, equivalences))) |
| 143 | } else { |
| 144 | Err((mfp.projection.len(), expr)) |
| 145 | } |
| 146 | }) |
no test coverage detected