You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "2010YOUY01 (via GitHub)" <gi...@apache.org> on 2023/06/01 18:27:07 UTC

[GitHub] [arrow-datafusion] 2010YOUY01 opened a new pull request, #6520: Add function name suggestion.

2010YOUY01 opened a new pull request, #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Part of https://github.com/apache/arrow-datafusion/issues/6396
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   When a wrong function name is given (possibly by typo, or missing underscore), suggest a similar valid function name:
   ```
   DataFusion CLI v25.0.0
   ❯ select arrowtypeof();
   Error during planning: Invalid function 'arrowtypeof'.
   Did you mean 'arrow_typeof'?
   ```
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   When [binding a function](https://github.com/apache/arrow-datafusion/blob/3907997cd0bcf24e1f4e50c272ec50265bc07c23/datafusion/sql/src/expr/function.rs#L34), parser only knows is this function a window function or non-window function.
   If it's non-window function, suggest the most similar function name from all `BuiltinScalarFunction` and `AggreagteFunction`
   If it's window function, suggest the most function name from all `AggregateFunction` and `BuiltinWindowFunction`
   Edit distance is used for the metric of similarity.
   
   # Are these changes tested?
   end-to-end sqllogictests are added.
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   No
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6520: Add function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#discussion_r1214679733


##########
datafusion/sql/src/expr/function.rs:
##########
@@ -84,73 +86,88 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             } else {
                 WindowFrame::new(!order_by.is_empty())
             };
-            let fun = self.find_window_func(&name)?;
-            let expr = match fun {
-                WindowFunction::AggregateFunction(aggregate_fun) => {
-                    let (aggregate_fun, args) = self.aggregate_fn_to_expr(
-                        aggregate_fun,
-                        function.args,
-                        schema,
-                        planner_context,
-                    )?;
-
-                    Expr::WindowFunction(expr::WindowFunction::new(
-                        WindowFunction::AggregateFunction(aggregate_fun),
-                        args,
+            if let Ok(fun) = self.find_window_func(&name) {

Review Comment:
   The whitespace blind diff also shows this nicely: https://github.com/apache/arrow-datafusion/pull/6520/files?w=1



##########
datafusion/expr/src/window_function.rs:
##########
@@ -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;

Review Comment:
   TIL https://docs.rs/strum_macros/0.24.3/strum_macros/derive.EnumIter.html -- very cool



##########
datafusion/expr/Cargo.toml:
##########
@@ -40,6 +40,7 @@ arrow = { workspace = true }
 datafusion-common = { path = "../common", version = "25.0.0" }
 lazy_static = { version = "^1.4.0" }
 sqlparser = "0.34"
+strsim = "0.10.0"

Review Comment:
   I reviewed this crate and it is widely used in the ecosystem (used by clap): https://crates.io/crates/strsim but hasn't been updated for 3 years
   
   However, it does appear to be a new dependency for datafusion,
   
   An alternate if we are worried about this new dependency is we could inline the definition of `levenshtein` into datafusion as it is not large
   
   https://github.com/dguo/strsim-rs/blob/65eac453cbd10ba4e13273002c843e95c81ae93f/src/lib.rs#L192-L238
   
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6520: Improve error messages with function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#discussion_r1215728844


##########
datafusion/common/src/utils.rs:
##########
@@ -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

Review Comment:
   👍  thank you for the link



##########
datafusion/common/src/utils.rs:
##########
@@ -383,7 +377,7 @@ pub mod datafusion_strsim {
     /// required to change one string into the other.
     ///
     /// ```
-    /// use strsim::levenshtein;
+    /// use datafusion_common::utils::datafusion_strsim::levenshtein;

Review Comment:
   👍 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ozankabak commented on pull request #6520: Improve error messages with function name suggestion.

Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1574152852

   If we are only using Levenshtein, inlining sounds good to me as it is only a small piece of code. I suggest using the full package only if we can see use cases where we'd use it more extensively in the future.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on pull request #6520: Improve error messages with function name suggestion.

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1574533074

   Thank you all for the feedback! Makes sense, the `strsim` external dependency is replaced with inlining.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #6520: Add function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1574141237

   cc @comphead  / @mingmwang  / @mustafasrepo / @ozankabak  if you have any thoughts on the new dependency?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on a diff in pull request #6520: Add function name suggestion.

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#discussion_r1213529737


##########
datafusion/sql/src/expr/function.rs:
##########
@@ -84,73 +86,88 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             } else {
                 WindowFrame::new(!order_by.is_empty())
             };
-            let fun = self.find_window_func(&name)?;
-            let expr = match fun {
-                WindowFunction::AggregateFunction(aggregate_fun) => {
-                    let (aggregate_fun, args) = self.aggregate_fn_to_expr(
-                        aggregate_fun,
-                        function.args,
-                        schema,
-                        planner_context,
-                    )?;
-
-                    Expr::WindowFunction(expr::WindowFunction::new(
-                        WindowFunction::AggregateFunction(aggregate_fun),
-                        args,
+            if let Ok(fun) = self.find_window_func(&name) {

Review Comment:
   The diff display on GitHub is not clear, it's just a simple refactor
   Before:
   ```rust
   if let Some(WindowType::WindowSpec(window)) = function.over.take() {
   		/* 1 */
   		let fun = self.find_window_func(&name)?;
   		/* 2 */
   		return ...;
   }
   
   /* 3 */
   
   // Return error
   Err(...)
   ```
   After:
   ```rust
   if let Some(WindowType::WindowSpec(window)) = function.over.take() {
   		/* 1 */
   		if let Ok(fun) = self.find_window_func(&name) {
   				/* 2 */
   				return ...;
   		}
   } else {
   		/* 3 */
   }
   
   // Return error
   Err(...)
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] comphead commented on pull request #6520: Improve error messages with function name suggestion.

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1574272074

   > If we are only using Levenshtein, inlining sounds good to me as it is only a small piece of code. I suggest using the full package only if we can see use cases where we'd use it more extensively in the future.
   
   Agree. the entire idea is neat to give a suggestion, however stale packages brings up not only future dependency conflicts but also unresolved security vulnerabilities. Perhaps we can replicate it from https://github.com/wooorm/levenshtein-rs ?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #6520: Add function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1572685811

   This looks awesome -- thank you @2010YOUY01  -- I plan to review this carefully tomorrow


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #6520: Improve error messages with function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520#issuecomment-1577344215

   Thanks again @2010YOUY01  and @ozankabak 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #6520: Improve error messages with function name suggestion.

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6520:
URL: https://github.com/apache/arrow-datafusion/pull/6520


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org