Skip to content

Commit 281408a

Browse files
committed
Fix assert when a scalar window func is given args
1 parent 9ce7b79 commit 281408a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/sql/src/plan/query.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,23 @@ fn plan_function<'a>(
47934793
partition_by,
47944794
scalar_args,
47954795
) = plan_window_function_non_aggr(ecx, f)?;
4796-
assert!(scalar_args.is_empty());
4796+
4797+
// All scalar window functions have 0 parameters. Let's print a nice error msg if the
4798+
// user gave some args. (The below `func::select_impl` would fail anyway, but the error
4799+
// msg there is less informative.)
4800+
if !scalar_args.is_empty() {
4801+
if let ResolvedItemName::Item {
4802+
full_name: FullItemName { item, .. },
4803+
..
4804+
} = name
4805+
{
4806+
sql_bail!(
4807+
"function {} has 0 parameters, but was called with {}",
4808+
item,
4809+
scalar_args.len()
4810+
);
4811+
}
4812+
}
47974813

47984814
// Note: the window frame doesn't affect scalar window funcs, but, strangely, we should
47994815
// accept a window frame here without an error msg. (Postgres also does this.)

test/sqllogictest/window_funcs.slt

+5
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ c
402402

403403
# rank and dense_rank
404404

405+
query error db error: ERROR: function rank has 0 parameters, but was called with 1
406+
WITH t (x) AS (VALUES ('a'), ('b'), ('c'))
407+
SELECT rank(x) OVER (ORDER BY x), dense_rank() OVER (ORDER BY x), x FROM t
408+
ORDER BY dense_rank;
409+
405410
query IIT
406411
WITH t (x) AS (VALUES ('a'), ('b'), ('c'))
407412
SELECT rank() OVER (ORDER BY x), dense_rank() OVER (ORDER BY x), x FROM t

0 commit comments

Comments
 (0)