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

Function plan_field_access

src/sql/src/plan/query.rs:4297–4324  ·  view source on GitHub ↗
(
    ecx: &ExprContext,
    expr: &Expr<Aug>,
    field: &Ident,
)

Source from the content-addressed store, hash-verified

4295}
4296
4297fn plan_field_access(
4298 ecx: &ExprContext,
4299 expr: &Expr<Aug>,
4300 field: &Ident,
4301) -> Result<CoercibleScalarExpr, PlanError> {
4302 let field = normalize::column_name(field.clone());
4303 let expr = plan_expr(ecx, expr)?.type_as_any(ecx)?;
4304 let ty = ecx.scalar_type(&expr);
4305 let i = match &ty {
4306 SqlScalarType::Record { fields, .. } => {
4307 fields.iter().position(|(name, _ty)| *name == field)
4308 }
4309 ty => sql_bail!(
4310 "column notation applied to type {}, which is not a composite type",
4311 ecx.humanize_sql_scalar_type(ty, false)
4312 ),
4313 };
4314 match i {
4315 None => sql_bail!(
4316 "field {} not found in data type {}",
4317 field,
4318 ecx.humanize_sql_scalar_type(&ty, false)
4319 ),
4320 Some(i) => Ok(expr
4321 .call_unary(UnaryFunc::RecordGet(expr_func::RecordGet(i)))
4322 .into()),
4323 }
4324}
4325
4326fn plan_subscript(
4327 ecx: &ExprContext,

Callers 1

plan_expr_innerFunction · 0.85

Calls 9

column_nameFunction · 0.85
plan_exprFunction · 0.85
RecordGetClass · 0.85
type_as_anyMethod · 0.80
cloneMethod · 0.45
scalar_typeMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45
call_unaryMethod · 0.45

Tested by

no test coverage detected