-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve error messages with function name suggestion. #6520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,6 +318,74 @@ impl<T: ?Sized> DataPtr for Arc<T> { | |
| } | ||
| } | ||
|
|
||
| /// Adopted from strsim-rs for string similarity metrics | ||
| pub mod datafusion_strsim { | ||
| // Source: https://github.com/dguo/strsim-rs/blob/master/src/lib.rs | ||
| // License: https://github.com/dguo/strsim-rs/blob/master/LICENSE | ||
| use std::cmp::min; | ||
| use std::str::Chars; | ||
|
|
||
| struct StringWrapper<'a>(&'a str); | ||
|
|
||
| impl<'a, 'b> IntoIterator for &'a StringWrapper<'b> { | ||
| type Item = char; | ||
| type IntoIter = Chars<'b>; | ||
|
|
||
| fn into_iter(self) -> Self::IntoIter { | ||
| self.0.chars() | ||
| } | ||
| } | ||
|
|
||
| /// Calculates the minimum number of insertions, deletions, and substitutions | ||
| /// required to change one sequence into the other. | ||
| fn generic_levenshtein<'a, 'b, Iter1, Iter2, Elem1, Elem2>( | ||
| a: &'a Iter1, | ||
| b: &'b Iter2, | ||
| ) -> usize | ||
| where | ||
| &'a Iter1: IntoIterator<Item = Elem1>, | ||
| &'b Iter2: IntoIterator<Item = Elem2>, | ||
| Elem1: PartialEq<Elem2>, | ||
| { | ||
| let b_len = b.into_iter().count(); | ||
|
|
||
| if a.into_iter().next().is_none() { | ||
| return b_len; | ||
| } | ||
|
|
||
| let mut cache: Vec<usize> = (1..b_len + 1).collect(); | ||
|
|
||
| let mut result = 0; | ||
|
|
||
| for (i, a_elem) in a.into_iter().enumerate() { | ||
| result = i + 1; | ||
| let mut distance_b = i; | ||
|
|
||
| for (j, b_elem) in b.into_iter().enumerate() { | ||
| let cost = if a_elem == b_elem { 0usize } else { 1usize }; | ||
| let distance_a = distance_b + cost; | ||
| distance_b = cache[j]; | ||
| result = min(result + 1, min(distance_a, distance_b + 1)); | ||
| cache[j] = result; | ||
| } | ||
| } | ||
|
|
||
| result | ||
| } | ||
|
|
||
| /// Calculates the minimum number of insertions, deletions, and substitutions | ||
| /// required to change one string into the other. | ||
| /// | ||
| /// ``` | ||
| /// use datafusion_common::utils::datafusion_strsim::levenshtein; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| /// | ||
| /// assert_eq!(3, levenshtein("kitten", "sitting")); | ||
| /// ``` | ||
| pub fn levenshtein(a: &str, b: &str) -> usize { | ||
| generic_levenshtein(&StringWrapper(a), &StringWrapper(b)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use arrow::array::Float64Array; | ||
|
|
||
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ use arrow::datatypes::DataType; | |
| use datafusion_common::{DataFusionError, Result}; | ||
| use std::sync::Arc; | ||
| use std::{fmt, str::FromStr}; | ||
| use strum_macros::EnumIter; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| /// WindowFunction | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
|
|
@@ -73,7 +74,7 @@ impl fmt::Display for WindowFunction { | |
| } | ||
|
|
||
| /// An aggregate function that is part of a built-in window function | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash, EnumIter)] | ||
| pub enum BuiltInWindowFunction { | ||
| /// number of the current row within its partition, counting from 1 | ||
| RowNumber, | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you for the link