(params: Vec<String>, body: Arc<dyn PhysicalExpr>)
| 75 | } |
| 76 | |
| 77 | fn new(params: Vec<String>, body: Arc<dyn PhysicalExpr>) -> Self { |
| 78 | let mut used_column_indices = HashSet::new(); |
| 79 | |
| 80 | body.apply(|node| { |
| 81 | if let Some(col) = node.downcast_ref::<Column>() { |
| 82 | used_column_indices.insert(col.index()); |
| 83 | } else if let Some(var) = node.downcast_ref::<LambdaVariable>() { |
| 84 | used_column_indices.insert(var.index()); |
| 85 | } |
| 86 | |
| 87 | Ok(TreeNodeRecursion::Continue) |
| 88 | }) |
| 89 | .expect("closure should be infallible"); |
| 90 | |
| 91 | let mut projection = used_column_indices.into_iter().collect::<Vec<_>>(); |
| 92 | |
| 93 | projection.sort(); |
| 94 | |
| 95 | let column_index_map = projection |
| 96 | .iter() |
| 97 | .enumerate() |
| 98 | .map(|(projected, original)| (*original, projected)) |
| 99 | .collect::<HashMap<_, _>>(); |
| 100 | |
| 101 | let projected_body = Arc::clone(&body) |
| 102 | .transform_down(|e| { |
| 103 | if let Some(column) = e.downcast_ref::<Column>() { |
| 104 | let original = column.index(); |
| 105 | let projected = *column_index_map.get(&original).unwrap(); |
| 106 | if projected != original { |
| 107 | return Ok(Transformed::yes(Arc::new(Column::new( |
| 108 | column.name(), |
| 109 | projected, |
| 110 | )))); |
| 111 | } |
| 112 | } else if let Some(lambda_variable) = e.downcast_ref::<LambdaVariable>() { |
| 113 | let original = lambda_variable.index(); |
| 114 | let projected = *column_index_map.get(&original).unwrap(); |
| 115 | if projected != original { |
| 116 | return Ok(Transformed::yes(Arc::new(LambdaVariable::new( |
| 117 | projected, |
| 118 | Arc::clone(lambda_variable.field()), |
| 119 | )))); |
| 120 | } |
| 121 | } |
| 122 | Ok(Transformed::no(e)) |
| 123 | }) |
| 124 | .expect("closure should be infallible") |
| 125 | .data; |
| 126 | |
| 127 | Self { |
| 128 | params, |
| 129 | body, |
| 130 | projected_body, |
| 131 | projection, |
| 132 | } |
| 133 | } |
| 134 |
nothing calls this directly
no test coverage detected