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,
)
| 44 | /// Returns `None` if no valid matches are found. This happens when there are no |
| 45 | /// functions registered with the context. |
| 46 | pub 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. |
no test coverage detected
searching dependent graphs…