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

Function replace_columns

datafusion/expr/src/logical_plan/builder.rs:2033–2049  ·  view source on GitHub ↗

If there is a REPLACE statement in the projected expression in the form of "REPLACE (some_column_within_an_expr AS some_column)", this function replaces that column with the given replace expression. Column name remains the same. Multiple REPLACEs are also possible with comma separations.

(
    mut exprs: Vec<Expr>,
    replace: &PlannedReplaceSelectItem,
)

Source from the content-addressed store, hash-verified

2031/// that column with the given replace expression. Column name remains the same.
2032/// Multiple REPLACEs are also possible with comma separations.
2033fn replace_columns(
2034 mut exprs: Vec<Expr>,
2035 replace: &PlannedReplaceSelectItem,
2036) -> Result<Vec<Expr>> {
2037 for expr in exprs.iter_mut() {
2038 if let Expr::Column(Column { name, .. }) = expr
2039 && let Some((_, new_expr)) = replace
2040 .items()
2041 .iter()
2042 .zip(replace.expressions().iter())
2043 .find(|(item, _)| item.column_name.value == *name)
2044 {
2045 *expr = new_expr.clone().alias(name.clone())
2046 }
2047 }
2048 Ok(exprs)
2049}
2050
2051/// Create a SubqueryAlias to wrap a LogicalPlan.
2052pub fn subquery_alias(

Callers 1

project_with_validationFunction · 0.85

Calls 5

iterMethod · 0.45
itemsMethod · 0.45
expressionsMethod · 0.45
aliasMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…