alamb commented on code in PR #14513:
URL: https://github.com/apache/datafusion/pull/14513#discussion_r1943025816


##########
datafusion/functions/src/utils.rs:
##########
@@ -18,10 +18,27 @@
 use arrow::array::ArrayRef;
 use arrow::datatypes::DataType;
 
-use datafusion_common::{Result, ScalarValue};
+use datafusion_common::{exec_datafusion_err, Result, ScalarValue};
 use datafusion_expr::function::Hint;
 use datafusion_expr::ColumnarValue;
 
+/// Converts a collection of function arguments into an fixed-size array of 
length N
+/// producing a reasonable error message in case of unexpected number of 
arguments.

Review Comment:
   This is very cool
   
   I though it was so cool I tried to write an example:
   
   ```suggestion
   /// producing a reasonable error message in case of unexpected number of 
arguments.
   ///
   /// # Example
   /// ```
   /// # use datafusion_common::ScalarValue;
   /// # use datafusion_common::Result;
   /// # use datafusion_expr_common::columnar_value::ColumnarValue;
   /// fn my_function(args: &[ColumnarValue]) -> Result<()> {
   ///   // function expects 2 args, so create a 2-element array
   ///   let [arg1, arg2] = take_function_args("my_function", args)?;
   ///   // ... do stuff..
   ///   Ok(())
   /// }
   /// 
   /// // Calling the function with 1 argument produces an error: 
   /// let ten = ColumnarValue::from(ScalarValue::from(10i32));
   /// let twenty = ColumnarValue::from(ScalarValue::from(20i32));
   /// let args = vec![ten.clone()];
   ///  let err = my_function(&args).unwrap_err();
   /// assert_eq!(err.to_string(), "my_function function requires 2 arguments, 
got 1");
   /// // Calling the function with 2 arguments works great
   /// let args = vec![ten, twenty];
   /// my_function(&args).unwrap();
   /// ```
   ```
   
   However, when I did I found this function is not exported publically
   
   ```
   error[E0425]: cannot find function `take_function_args` in this scope
    --> datafusion/functions/src/utils.rs:35:22
     |
   8 |   let [arg1, arg2] = take_function_args("my_function", args)?;
     |                      ^^^^^^^^^^^^^^^^^^ not found in this scope
   ```
   
   I think this is because utils isn't `pub` exported:
   
https://github.com/apache/datafusion/blob/ddee4717af08e1cbeddf32f2872c3b6c8d378618/datafusion/functions/src/lib.rs#L141-L140
   
   I suggest we publically export `util` and this method too 
   
   Can of course be done in a follow on PR



-- 
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-unsubscr...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to