MCPcopy Create free account
hub / github.com/apache/datafusion / rewrite_expr

Function rewrite_expr

datafusion/optimizer/src/optimize_projections/mod.rs:685–717  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

683/// --Source(a, b)
684/// ```
685fn 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.

Callers 2

optimize_internalMethod · 0.50

Calls 8

AliasClass · 0.85
transform_upMethod · 0.80
index_of_columnMethod · 0.80
unalias_nestedMethod · 0.80
mapMethod · 0.45
as_refMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…