Injects column aliases into the projection of a logical plan by wrapping expressions with `Expr::Alias` using the provided list of aliases. Example: - `SELECT col1, col2 FROM table` with aliases `["alias_1", "some_alias_2"]` will be transformed to - `SELECT col1 AS alias_1, col2 AS some_alias_2 FROM table`
(
projection: &Projection,
aliases: impl IntoIterator<Item = Ident>,
)
| 462 | /// - `SELECT col1, col2 FROM table` with aliases `["alias_1", "some_alias_2"]` will be transformed to |
| 463 | /// - `SELECT col1 AS alias_1, col2 AS some_alias_2 FROM table` |
| 464 | pub(super) fn inject_column_aliases( |
| 465 | projection: &Projection, |
| 466 | aliases: impl IntoIterator<Item = Ident>, |
| 467 | ) -> LogicalPlan { |
| 468 | let mut updated_projection = projection.clone(); |
| 469 | |
| 470 | let new_exprs = updated_projection |
| 471 | .expr |
| 472 | .into_iter() |
| 473 | .zip(aliases) |
| 474 | .map(|(expr, col_alias)| { |
| 475 | let relation = match &expr { |
| 476 | Expr::Column(col) => col.relation.clone(), |
| 477 | _ => None, |
| 478 | }; |
| 479 | |
| 480 | Expr::Alias(Alias { |
| 481 | expr: Box::new(expr.clone()), |
| 482 | relation, |
| 483 | name: col_alias.value, |
| 484 | metadata: None, |
| 485 | }) |
| 486 | }) |
| 487 | .collect::<Vec<_>>(); |
| 488 | |
| 489 | updated_projection.expr = new_exprs; |
| 490 | |
| 491 | LogicalPlan::Projection(updated_projection) |
| 492 | } |
| 493 | |
| 494 | fn find_projection(logical_plan: &LogicalPlan) -> Option<&Projection> { |
| 495 | match logical_plan { |
no test coverage detected
searching dependent graphs…