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

Function find_closest_match

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

Find the closest matching string to the target string in the candidates list, using edit distance(case insensitive) Input `candidates` must not be empty otherwise an error is returned.

(candidates: Vec<String>, target: &str)

Source from the content-addressed store, hash-verified

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.
74fn find_closest_match(candidates: Vec<String>, target: &str) -> Option<String> {
75 let target = target.to_lowercase();
76 candidates.into_iter().min_by_key(|candidate| {
77 datafusion_common::utils::datafusion_strsim::levenshtein(
78 &candidate.to_lowercase(),
79 &target,
80 )
81 })
82}
83
84/// Arguments for a function call extracted from the SQL AST
85#[derive(Debug)]

Callers 1

suggest_valid_functionFunction · 0.85

Calls 2

levenshteinFunction · 0.50
into_iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…