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

Function columnize_expr

datafusion/expr/src/utils.rs:782–797  ·  view source on GitHub ↗

Convert an expression into Column expression if it's already provided as input plan. For example, it rewrites: ```text .aggregate(vec![col("c1")], vec![sum(col("c2"))])? .project(vec![col("c1"), sum(col("c2"))? ``` Into: ```text .aggregate(vec![col("c1")], vec![sum(col("c2"))])? .project(vec![col("c1"), col("SUM(c2)")? ```

(e: Expr, input: &LogicalPlan)

Source from the content-addressed store, hash-verified

780/// .project(vec![col("c1"), col("SUM(c2)")?
781/// ```
782pub fn columnize_expr(e: Expr, input: &LogicalPlan) -> Result<Expr> {
783 let output_exprs = match input.columnized_output_exprs() {
784 Ok(exprs) if !exprs.is_empty() => exprs,
785 _ => return Ok(e),
786 };
787 let exprs_map: HashMap<&Expr, Column> = output_exprs.into_iter().collect();
788 e.transform_down(|node: Expr| match exprs_map.get(&node) {
789 Some(column) => Ok(Transformed::new(
790 Expr::Column(column.clone()),
791 true,
792 TreeNodeRecursion::Jump,
793 )),
794 None => Ok(Transformed::no(node)),
795 })
796 .data()
797}
798
799/// Collect all deeply nested `Expr::Column`'s. They are returned in order of
800/// appearance (depth first), and may contain duplicates.

Calls 10

newFunction · 0.85
collectMethod · 0.80
transform_downMethod · 0.80
ColumnClass · 0.50
is_emptyMethod · 0.45
into_iterMethod · 0.45
dataMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…