(
ecx: &ExprContext,
f @ Function {
name,
args,
filter,
over,
distinct,
}: &'a Function<Aug>,
)
| 5427 | } |
| 5428 | |
| 5429 | fn plan_function<'a>( |
| 5430 | ecx: &ExprContext, |
| 5431 | f @ Function { |
| 5432 | name, |
| 5433 | args, |
| 5434 | filter, |
| 5435 | over, |
| 5436 | distinct, |
| 5437 | }: &'a Function<Aug>, |
| 5438 | ) -> Result<HirScalarExpr, PlanError> { |
| 5439 | let impls = match resolve_func(ecx, name, args)? { |
| 5440 | Func::Table(_) => { |
| 5441 | sql_bail!( |
| 5442 | "table functions are not allowed in {} (function {})", |
| 5443 | ecx.name, |
| 5444 | name |
| 5445 | ); |
| 5446 | } |
| 5447 | Func::Scalar(impls) => { |
| 5448 | if over.is_some() { |
| 5449 | sql_bail!( |
| 5450 | "OVER clause not allowed on {name}. The OVER clause can only be used with window functions (including aggregations)." |
| 5451 | ); |
| 5452 | } |
| 5453 | impls |
| 5454 | } |
| 5455 | Func::ScalarWindow(impls) => { |
| 5456 | let ( |
| 5457 | ignore_nulls, |
| 5458 | order_by_exprs, |
| 5459 | col_orders, |
| 5460 | _window_frame, |
| 5461 | partition_by, |
| 5462 | scalar_args, |
| 5463 | ) = plan_window_function_non_aggr(ecx, f)?; |
| 5464 | |
| 5465 | // All scalar window functions have 0 parameters. Let's print a nice error msg if the |
| 5466 | // user gave some args. (The below `func::select_impl` would fail anyway, but the error |
| 5467 | // msg there is less informative.) |
| 5468 | if !scalar_args.is_empty() { |
| 5469 | if let ResolvedItemName::Item { |
| 5470 | full_name: FullItemName { item, .. }, |
| 5471 | .. |
| 5472 | } = name |
| 5473 | { |
| 5474 | sql_bail!( |
| 5475 | "function {} has 0 parameters, but was called with {}", |
| 5476 | item, |
| 5477 | scalar_args.len() |
| 5478 | ); |
| 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | // Note: the window frame doesn't affect scalar window funcs, but, strangely, we should |
| 5483 | // accept a window frame here without an error msg. (Postgres also does this.) |
| 5484 | // TODO: maybe we should give a notice |
| 5485 | |
| 5486 | let func = func::select_impl(ecx, FuncSpec::Func(name), impls, scalar_args, vec![])?; |
no test coverage detected