MCPcopy Create free account
hub / github.com/apache/datafusion / suggest_valid_function

Function suggest_valid_function

datafusion/sql/src/expr/function.rs:46–70  ·  view source on GitHub ↗

Suggest a valid function based on an invalid input function name Returns `None` if no valid matches are found. This happens when there are no functions registered with the context.

(
    input_function_name: &str,
    is_window_func: bool,
    ctx: &dyn ContextProvider,
)

Source from the content-addressed store, hash-verified

44/// Returns `None` if no valid matches are found. This happens when there are no
45/// functions registered with the context.
46pub fn suggest_valid_function(
47 input_function_name: &str,
48 is_window_func: bool,
49 ctx: &dyn ContextProvider,
50) -> Option<String> {
51 let valid_funcs = if is_window_func {
52 // All aggregate functions and builtin window functions
53 let mut funcs = Vec::new();
54
55 funcs.extend(ctx.udaf_names());
56 funcs.extend(ctx.udwf_names());
57
58 funcs
59 } else {
60 // All scalar functions and aggregate functions
61 let mut funcs = Vec::new();
62
63 funcs.extend(ctx.udf_names());
64 funcs.extend(ctx.higher_order_function_names());
65 funcs.extend(ctx.udaf_names());
66
67 funcs
68 };
69 find_closest_match(valid_funcs, input_function_name)
70}
71
72/// Find the closest matching string to the target string in the candidates list, using edit distance(case insensitive)
73/// Input `candidates` must not be empty otherwise an error is returned.

Callers 1

sql_function_to_exprMethod · 0.85

Calls 7

newFunction · 0.85
find_closest_matchFunction · 0.85
extendMethod · 0.45
udaf_namesMethod · 0.45
udwf_namesMethod · 0.45
udf_namesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…