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

Function window_expr_common_partition_keys

datafusion/sql/src/utils.rs:256–285  ·  view source on GitHub ↗

Given a slice of window expressions sharing the same sort key, find their common partition keys.

(window_exprs: &[Expr])

Source from the content-addressed store, hash-verified

254/// Given a slice of window expressions sharing the same sort key, find their common partition
255/// keys.
256pub 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

Callers

nothing calls this directly

Calls 4

mapMethod · 0.45
iterMethod · 0.45
as_refMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…