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

Function plan_solitary_table_function

src/sql/src/plan/query.rs:3228–3274  ·  view source on GitHub ↗

Plans a table function that appears alone, i.e., that is not part of a `ROWS FROM` clause that contains other table functions. Special aliasing rules apply.

(
    qcx: &QueryContext,
    function: &Function<Aug>,
    alias: Option<&TableAlias>,
    with_ordinality: bool,
)

Source from the content-addressed store, hash-verified

3226/// FROM` clause that contains other table functions. Special aliasing rules
3227/// apply.
3228fn plan_solitary_table_function(
3229 qcx: &QueryContext,
3230 function: &Function<Aug>,
3231 alias: Option<&TableAlias>,
3232 with_ordinality: bool,
3233) -> Result<(HirRelationExpr, Scope), PlanError> {
3234 let (expr, mut scope) = plan_table_function_internal(qcx, function, with_ordinality, None)?;
3235
3236 let single_column_function = scope.len() == 1 + if with_ordinality { 1 } else { 0 };
3237 if single_column_function {
3238 let item = &mut scope.items[0];
3239
3240 // Mark that the function only produced a single column. This impacts
3241 // whole-row references.
3242 item.from_single_column_function = true;
3243
3244 // Strange special case for solitary table functions that output one
3245 // column whose name matches the name of the table function. If a table
3246 // alias is provided, the column name is changed to the table alias's
3247 // name. Concretely, the following query returns a column named `x`
3248 // rather than a column named `generate_series`:
3249 //
3250 // SELECT * FROM generate_series(1, 5) AS x
3251 //
3252 // Note that this case does not apply to e.g. `jsonb_array_elements`,
3253 // since its output column is explicitly named `value`, not
3254 // `jsonb_array_elements`.
3255 //
3256 // Note also that we may (correctly) change the column name again when
3257 // we plan the table alias below if the `alias.columns` is non-empty.
3258 if let Some(alias) = alias {
3259 if let ScopeItem {
3260 table_name: Some(table_name),
3261 column_name,
3262 ..
3263 } = item
3264 {
3265 if table_name.item.as_str() == column_name.as_str() {
3266 *column_name = normalize::column_name(alias.name.clone());
3267 }
3268 }
3269 }
3270 }
3271
3272 let scope = plan_table_alias(scope, alias)?;
3273 Ok((expr, scope))
3274}
3275
3276/// Plans a table function.
3277///

Callers 3

plan_scalar_table_funcsFunction · 0.85
plan_table_factorFunction · 0.85
plan_rows_fromFunction · 0.85

Calls 6

column_nameFunction · 0.85
plan_table_aliasFunction · 0.85
lenMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected