Repository navigation
fix: add edit-distance threshold and deterministic tie-breaking to su… - #27674
Merged
alamb merged 2 commits intoNov 28, 2026
Merged
Conversation
…ggest_valid_function
2010YOUY01
approved these changes
Nov 24, 2026
2010YOUY01
left a comment
Member
There was a problem hiding this comment.
This is a nice error message improvement. Thank you!
alamb
approved these changes
Nov 25, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
Thanks @rctruta and @2010YOUY01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
suggest_valid_functionis non-deterministic and has no edit-distance threshold #27673Rationale for this change
suggest_valid_function/find_closest_matchindatafusion/sql/src/expr/function.rscurrently:"Did you mean ..."suggestions (e.g.,zzzzzzzzzz()->'list_zip').HashSet-backed function names withIterator::min_by_key, making tie-breaking non-deterministic across processes (e.g.,date('1995-03-15')randomly suggeststanh,atan,rand,abs,cot,map,range, orto_date).Nonefromsuggest_valid_functionat the call site asinternal_err!("No functions registered with this context."), preventingNonefrom representing "no close match".What changes are included in this PR?
datafusion/sql/src/expr/function.rs:find_closest_matchto uselevenshtein_with_buffer, reject candidates wheremax_len == 0 || distance * 2 >= max_len(analogous toclosest_valid_fieldindatafusion/common/src/error.rs, strictly requiring< 50%edits so exact-50% false positives likeyear->meanare also filtered out), and break ties deterministically by(distance, Reverse(max_len), candidate_lower).suggest_valid_function, returningPlanError("Invalid function '<name>'.")(with diagnostic span and no note) when no candidate is close enough.expr::function::tests::test_find_closest_match_threshold_and_determinism.datafusion/sql/tests/cases/diagnostic.rs:test_invalid_functioninto a close-typo case (conca->concat) and a far-distance case (concat_not_exist-> empty notes).datafusion/sqllogictest/test_files/functions.slt:SELECT date('1995-03-15')(deterministically suggestingto_date) andSELECT zzzzzzzzzz()(no suggestion).Are these changes tested?
Yes:
cargo test -p datafusion-sql(104 unit tests, 613 integration tests, 12 doc-tests)cargo test -p datafusion-sqllogictest --test sqllogictests -- functions.slt errors.sltcargo clippy -p datafusion-sql --all-targets --no-deps -- -D warningscargo fmt -p datafusion-sql -- --checkAre there any user-facing changes?
Unknown SQL function errors no longer emit non-deterministic or unrelated
"Did you mean ..."suggestions when no registered function is within the edit-distance threshold.