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

Function find_agg_expr

datafusion/sql/src/unparser/utils.rs:268–290  ·  view source on GitHub ↗
(agg: &'a Aggregate, column: &Column)

Source from the content-addressed store, hash-verified

266}
267
268fn find_agg_expr<'a>(agg: &'a Aggregate, column: &Column) -> Result<Option<&'a Expr>> {
269 if let Ok(index) = agg.schema.index_of_column(column) {
270 if matches!(agg.group_expr.as_slice(), [Expr::GroupingSet(_)]) {
271 // For grouping set expr, we must operate by expression list from the grouping set
272 let grouping_expr = grouping_set_to_exprlist(agg.group_expr.as_slice())?;
273 match index.cmp(&grouping_expr.len()) {
274 Ordering::Less => Ok(grouping_expr.into_iter().nth(index)),
275 Ordering::Equal => {
276 internal_err!(
277 "Tried to unproject column referring to internal grouping id"
278 )
279 }
280 Ordering::Greater => {
281 Ok(agg.aggr_expr.get(index - grouping_expr.len() - 1))
282 }
283 }
284 } else {
285 Ok(agg.group_expr.iter().chain(agg.aggr_expr.iter()).nth(index))
286 }
287 } else {
288 Ok(None)
289 }
290}
291
292fn find_window_expr<'a>(
293 windows: &'a [&'a Window],

Callers 1

unproject_agg_exprsFunction · 0.85

Calls 8

grouping_set_to_exprlistFunction · 0.85
index_of_columnMethod · 0.80
nthMethod · 0.80
cmpMethod · 0.45
lenMethod · 0.45
into_iterMethod · 0.45
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…