Skip to content

Commit 79c22d6

Browse files
authored
Search default window functions if no session context was provided (#963)
* Search default window functions if no session context was provided * Check if value is None because [] don't trigger the intended behavior
1 parent 5c83493 commit 79c22d6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

python/datafusion/dataframe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,14 @@ def join(
446446
left_on = join_keys[0]
447447
right_on = join_keys[1]
448448

449-
if on:
450-
if left_on or right_on:
449+
if on is not None:
450+
if left_on is not None or right_on is not None:
451451
raise ValueError(
452452
"`left_on` or `right_on` should not provided with `on`"
453453
)
454454
left_on = on
455455
right_on = on
456-
elif left_on or right_on:
456+
elif left_on is not None or right_on is not None:
457457
if left_on is None or right_on is None:
458458
raise ValueError("`left_on` and `right_on` should both be provided.")
459459
else:

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)