risingwave_frontend::expr

Function infer_type_name

source
pub fn infer_type_name<'a>(
    sig_map: &'a FunctionRegistry,
    func_name: FuncName,
    inputs: &[Option<DataType>],
) -> Result<&'a FuncSign, RwError>
Expand description

From all available functions in sig_map, find and return the best matching FuncSign for the provided func_name and inputs. This not only support exact function signature match, but can also match substr(varchar, smallint) or even substr(varchar, unknown) to substr(varchar, int).

This corresponds to the PostgreSQL rules on operators and functions here:

To summarize,

  1. Find all functions with matching func_name and argument count.
  2. For binary operator with unknown on exactly one side, try to find an exact match assuming both sides are same type.
  3. Rank candidates based on most matching positions. This covers Rule 2, 4a, 4c and 4d in PostgreSQL. See top_matches for details.
  4. Attempt to narrow down candidates by selecting type categories for unknowns. This covers Rule 4e in PostgreSQL. See narrow_category for details.
  5. Attempt to narrow down candidates by assuming all arguments are same type. This covers Rule 4f in PostgreSQL. See narrow_same_type for details.