Rewrites a projection expression using the projection before it (i.e. its input) This is a subroutine to the `merge_consecutive_projections` function. # Parameters `expr` - A reference to the expression to rewrite. `input` - A reference to the input of the projection expression (itself a projection). # Returns A `Result` object with the following semantics: - `Ok(Some(Expr))`: Rewrite was suc
(expr: Expr, input: &Projection)
| 683 | /// --Source(a, b) |
| 684 | /// ``` |
| 685 | fn rewrite_expr(expr: Expr, input: &Projection) -> Result<Transformed<Expr>> { |
| 686 | expr.transform_up(|expr| { |
| 687 | match expr { |
| 688 | // remove any intermediate aliases if they do not carry metadata |
| 689 | Expr::Alias(alias) => { |
| 690 | match alias |
| 691 | .metadata |
| 692 | .as_ref() |
| 693 | .map(|h| h.is_empty()) |
| 694 | .unwrap_or(true) |
| 695 | { |
| 696 | true => Ok(Transformed::yes(*alias.expr)), |
| 697 | false => Ok(Transformed::no(Expr::Alias(alias))), |
| 698 | } |
| 699 | } |
| 700 | Expr::Column(col) => { |
| 701 | // Find index of column: |
| 702 | let idx = input.schema.index_of_column(&col)?; |
| 703 | // get the corresponding unaliased input expression |
| 704 | // |
| 705 | // For example: |
| 706 | // * the input projection is [`a + b` as c, `d + e` as f] |
| 707 | // * the current column is an expression "f" |
| 708 | // |
| 709 | // return the expression `d + e` (not `d + e` as f) |
| 710 | let input_expr = input.expr[idx].clone().unalias_nested().data; |
| 711 | Ok(Transformed::yes(input_expr)) |
| 712 | } |
| 713 | // Unsupported type for consecutive projection merge analysis. |
| 714 | _ => Ok(Transformed::no(expr)), |
| 715 | } |
| 716 | }) |
| 717 | } |
| 718 | |
| 719 | /// Splits requirement indices for a join into left and right children based on |
| 720 | /// the join type. |
no test coverage detected
searching dependent graphs…