n0r0shi opened a new issue, #20488:
URL: https://github.com/apache/datafusion/issues/20488
### Is your feature request related to a problem or challenge?
## Is your feature request related to a problem or challenge?
DataFusion's `levenshtein` function currently only supports the 2-argument
form `levenshtein(str1, str2)`. Apache Spark supports a 3-argument form
`levenshtein(str1, str2, threshold)` that returns -1 if the edit distance
exceeds the threshold, with early termination for better performance.
This missing feature causes downstream projects like [Apache DataFusion
Comet](https://github.com/apache/datafusion-comet) to fall back to Spark for
queries using the threshold form (see [Comet
#3084](https://github.com/apache/datafusion-comet/issues/3084)).
## Describe the solution you'd like
Add an optional third `Int32` argument to `levenshtein`:
```sql
SELECT levenshtein('kitten', 'sitting', 2); -- -1 (distance 3 >
threshold 2)
SELECT levenshtein('kitten', 'sitting', 5); -- 3 (distance 3 <=
threshold 5)
SELECT levenshtein('kitten', 'sitting', NULL); -- NULL
```
The threshold variant should use a banded DP algorithm with early
termination for better performance when the threshold is small relative to
string lengths.
### Additional context
Spark's implementation is in UTF8String.levenshteinDistance, based on
Apache Commons Text LevenshteinDistance.limitedCompare.
### Describe the solution you'd like
_No response_
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]