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

Function resolve_func

src/sql/src/plan/query.rs:5645–5684  ·  view source on GitHub ↗

Resolves the name to a set of function implementations. If the name does not specify a known built-in function, returns an error.

(
    ecx: &ExprContext,
    name: &ResolvedItemName,
    args: &mz_sql_parser::ast::FunctionArgs<Aug>,
)

Source from the content-addressed store, hash-verified

5643///
5644/// If the name does not specify a known built-in function, returns an error.
5645pub fn resolve_func(
5646 ecx: &ExprContext,
5647 name: &ResolvedItemName,
5648 args: &mz_sql_parser::ast::FunctionArgs<Aug>,
5649) -> Result<&'static Func, PlanError> {
5650 if let Ok(i) = ecx.qcx.scx.get_item_by_resolved_name(name) {
5651 if let Ok(f) = i.func() {
5652 return Ok(f);
5653 }
5654 }
5655
5656 // Couldn't resolve function with this name, so generate verbose error
5657 // message.
5658 let cexprs = match args {
5659 mz_sql_parser::ast::FunctionArgs::Star => vec![],
5660 mz_sql_parser::ast::FunctionArgs::Args { args, order_by } => {
5661 if !order_by.is_empty() {
5662 sql_bail!(
5663 "ORDER BY specified, but {} is not an aggregate function",
5664 name
5665 );
5666 }
5667 plan_exprs(ecx, args)?
5668 }
5669 };
5670
5671 let arg_types: Vec<_> = cexprs
5672 .into_iter()
5673 .map(|ty| match ecx.scalar_type(&ty) {
5674 CoercibleScalarType::Coerced(ty) => ecx.humanize_sql_scalar_type(&ty, false),
5675 CoercibleScalarType::Record(_) => "record".to_string(),
5676 CoercibleScalarType::Uncoerced => "unknown".to_string(),
5677 })
5678 .collect();
5679
5680 Err(PlanError::UnknownFunction {
5681 name: name.to_string(),
5682 arg_types,
5683 })
5684}
5685
5686fn plan_is_expr<'a>(
5687 ecx: &ExprContext,

Callers 3

plan_aggregate_commonFunction · 0.85
plan_functionFunction · 0.85

Calls 10

plan_exprsFunction · 0.85
funcMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
scalar_typeMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected