Skip to content

Commit 3bd30a0

Browse files
committed
Search default window functions if no session context was provided
1 parent 5c83493 commit 3bd30a0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

python/datafusion/functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def window(
431431
partition_by = expr_list_to_raw_expr_list(partition_by)
432432
order_by_raw = sort_list_to_raw_sort_list(order_by)
433433
window_frame = window_frame.window_frame if window_frame is not None else None
434+
ctx = ctx.ctx if ctx is not None else None
434435
return Expr(f.window(name, args, partition_by, order_by_raw, window_frame, ctx))
435436

436437

src/functions.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use datafusion::functions_aggregate::all_default_aggregate_functions;
19+
use datafusion::functions_window::all_default_window_functions;
1920
use datafusion::logical_expr::ExprFunctionExt;
2021
use datafusion::logical_expr::WindowFrame;
2122
use pyo3::{prelude::*, wrap_pyfunction};
@@ -282,6 +283,16 @@ fn find_window_fn(name: &str, ctx: Option<PySessionContext>) -> PyResult<WindowF
282283
return Ok(agg_fn);
283284
}
284285

286+
// search default window functions
287+
let window_fn = all_default_window_functions()
288+
.iter()
289+
.find(|v| v.name() == name || v.aliases().contains(&name.to_string()))
290+
.map(|f| WindowFunctionDefinition::WindowUDF(f.clone()));
291+
292+
if let Some(window_fn) = window_fn {
293+
return Ok(window_fn);
294+
}
295+
285296
Err(DataFusionError::Common(format!("window function `{name}` not found")).into())
286297
}
287298

0 commit comments

Comments
 (0)