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

Function unproject_agg_exprs

datafusion/sql/src/unparser/utils.rs:222–246  ·  view source on GitHub ↗

Recursively identify all Column expressions and transform them into the appropriate aggregate expression contained in agg. For example, if expr contains the column expr "COUNT(*)" it will be transformed into an actual aggregate expression COUNT(*) as identified in the aggregate node.

(
    expr: Expr,
    agg: &Aggregate,
    windows: Option<&[&Window]>,
)

Source from the content-addressed store, hash-verified

220/// For example, if expr contains the column expr "COUNT(*)" it will be transformed
221/// into an actual aggregate expression COUNT(*) as identified in the aggregate node.
222pub(crate) fn unproject_agg_exprs(
223 expr: Expr,
224 agg: &Aggregate,
225 windows: Option<&[&Window]>,
226) -> Result<Expr> {
227 expr.transform(|sub_expr| {
228 if let Expr::Column(c) = sub_expr {
229 if let Some(unprojected_expr) = find_agg_expr(agg, &c)? {
230 Ok(Transformed::yes(unprojected_expr.clone()))
231 } else if let Some(unprojected_expr) =
232 windows.and_then(|w| find_window_expr(w, &c.name).cloned())
233 {
234 // Window function can contain an aggregation columns, e.g., 'avg(sum(ss_sales_price)) over ...' that needs to be unprojected
235 Ok(Transformed::yes(unproject_agg_exprs(unprojected_expr, agg, None)?))
236 } else {
237 internal_err!(
238 "Tried to unproject agg expr for column '{}' that was not found in the provided Aggregate!", &c.name
239 )
240 }
241 } else {
242 Ok(Transformed::no(sub_expr))
243 }
244 })
245 .map(|e| e.data)
246}
247
248/// Recursively identify all Column expressions and transform them into the appropriate
249/// window expression contained in window.

Callers 4

unproject_sort_exprFunction · 0.85
project_window_outputMethod · 0.85

Calls 6

find_agg_exprFunction · 0.85
find_window_exprFunction · 0.85
mapMethod · 0.45
transformMethod · 0.45
cloneMethod · 0.45
clonedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…