Given a slice of window expressions sharing the same sort key, find their common partition keys.
(window_exprs: &[Expr])
| 254 | /// Given a slice of window expressions sharing the same sort key, find their common partition |
| 255 | /// keys. |
| 256 | pub fn window_expr_common_partition_keys(window_exprs: &[Expr]) -> Result<&[Expr]> { |
| 257 | let all_partition_keys = window_exprs |
| 258 | .iter() |
| 259 | .map(|expr| match expr { |
| 260 | Expr::WindowFunction(window_fun) => { |
| 261 | let WindowFunction { |
| 262 | params: WindowFunctionParams { partition_by, .. }, |
| 263 | .. |
| 264 | } = window_fun.as_ref(); |
| 265 | Ok(partition_by) |
| 266 | } |
| 267 | Expr::Alias(Alias { expr, .. }) => match expr.as_ref() { |
| 268 | Expr::WindowFunction(window_fun) => { |
| 269 | let WindowFunction { |
| 270 | params: WindowFunctionParams { partition_by, .. }, |
| 271 | .. |
| 272 | } = window_fun.as_ref(); |
| 273 | Ok(partition_by) |
| 274 | } |
| 275 | expr => exec_err!("Impossibly got non-window expr {expr:?}"), |
| 276 | }, |
| 277 | expr => exec_err!("Impossibly got non-window expr {expr:?}"), |
| 278 | }) |
| 279 | .collect::<Result<Vec<_>>>()?; |
| 280 | let result = all_partition_keys |
| 281 | .iter() |
| 282 | .min_by_key(|s| s.len()) |
| 283 | .ok_or_else(|| exec_datafusion_err!("No window expressions found"))?; |
| 284 | Ok(result) |
| 285 | } |
| 286 | |
| 287 | /// Returns a validated `DataType` for the specified precision and |
| 288 | /// scale |