Plans a table function. You generally should call `plan_rows_from` or `plan_solitary_table_function` instead to get the appropriate aliasing behavior.
(
qcx: &QueryContext,
Function {
name,
args,
filter,
over,
distinct,
}: &Function<Aug>,
with_ordinality: bool,
table_name: Option<FullItemNa
| 3278 | /// You generally should call `plan_rows_from` or `plan_solitary_table_function` |
| 3279 | /// instead to get the appropriate aliasing behavior. |
| 3280 | fn plan_table_function_internal( |
| 3281 | qcx: &QueryContext, |
| 3282 | Function { |
| 3283 | name, |
| 3284 | args, |
| 3285 | filter, |
| 3286 | over, |
| 3287 | distinct, |
| 3288 | }: &Function<Aug>, |
| 3289 | with_ordinality: bool, |
| 3290 | table_name: Option<FullItemName>, |
| 3291 | ) -> Result<(HirRelationExpr, Scope), PlanError> { |
| 3292 | // The parser rejects FILTER, OVER, and DISTINCT in every table function |
| 3293 | // position (`FROM f(...)`, `ROWS FROM (...)`), and table functions in |
| 3294 | // scalar position are only lifted into a `FROM` clause when all three are |
| 3295 | // absent, so these are defensive. |
| 3296 | if filter.is_some() { |
| 3297 | sql_bail!("FILTER is not allowed for table functions in FROM"); |
| 3298 | } |
| 3299 | if over.is_some() { |
| 3300 | sql_bail!("OVER is not allowed for table functions in FROM"); |
| 3301 | } |
| 3302 | if *distinct { |
| 3303 | sql_bail!("DISTINCT is not allowed for table functions in FROM"); |
| 3304 | } |
| 3305 | |
| 3306 | let ecx = &ExprContext { |
| 3307 | qcx, |
| 3308 | name: "table function arguments", |
| 3309 | scope: &Scope::empty(), |
| 3310 | relation_type: &SqlRelationType::empty(), |
| 3311 | allow_aggregates: false, |
| 3312 | allow_subqueries: true, |
| 3313 | allow_parameters: true, |
| 3314 | allow_windows: false, |
| 3315 | }; |
| 3316 | |
| 3317 | let scalar_args = match args { |
| 3318 | FunctionArgs::Star => sql_bail!("{} does not accept * as an argument", name), |
| 3319 | FunctionArgs::Args { args, order_by } => { |
| 3320 | if !order_by.is_empty() { |
| 3321 | sql_bail!( |
| 3322 | "ORDER BY specified, but {} is not an aggregate function", |
| 3323 | name |
| 3324 | ); |
| 3325 | } |
| 3326 | plan_exprs(ecx, args)? |
| 3327 | } |
| 3328 | }; |
| 3329 | |
| 3330 | let table_name = match table_name { |
| 3331 | Some(table_name) => table_name.item, |
| 3332 | None => name.full_item_name().item.clone(), |
| 3333 | }; |
| 3334 | |
| 3335 | let scope_name = Some(PartialItemName { |
| 3336 | database: None, |
| 3337 | schema: None, |
no test coverage detected