MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_table_function_internal

Function plan_table_function_internal

src/sql/src/plan/query.rs:3280–3438  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3278/// You generally should call `plan_rows_from` or `plan_solitary_table_function`
3279/// instead to get the appropriate aliasing behavior.
3280fn 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,

Callers 2

plan_rows_from_internalFunction · 0.85

Calls 15

plan_exprsFunction · 0.85
resolve_funcFunction · 0.85
select_implFunction · 0.85
column_nameFunction · 0.85
is_someMethod · 0.80
full_item_nameMethod · 0.80
FuncEnum · 0.50
is_emptyMethod · 0.45
cloneMethod · 0.45
mapMethod · 0.45
typMethod · 0.45

Tested by

no test coverage detected