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]>,
)
| 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. |
| 222 | pub(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. |
no test coverage detected
searching dependent graphs…