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

   # 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.
   -->
   
   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.  
   -->
   Currently, the error message for the built-in scalar function signature 
mismatch is not straightforward.
   The error message before and after this change is shown below:
   (There are 5 different function signature types(variadic, exact...) from 
internal implementation, 1 function is chosen from each type)
   ```
   [BEFORE]DataFusion CLI v25.0.0
   ❯ select concat();
   Internal error: Builtin scalar function concat does not support empty 
arguments. This was likely caused by a bug in DataFusion's code and we would 
welcome that you file an bug report in our issue tracker
   ❯ SELECT nullif(1);
   Error during planning: Coercion from [Int64] to the signature Uniform(2, 
[Boolean, UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, 
Float64, Utf8, LargeUtf8]) failed.
   ❯ SELECT pi(3.14);
   Error during planning: Coercion from [Float64] to the signature Exact([]) 
failed.
   ❯ SELECT arrow_typeof(1, 1);
   Error during planning: The function expected 1 arguments but received 2
   ❯ SELECT power('1', '2');
   Error during planning: Coercion from [Utf8, Utf8] to the signature 
OneOf([Exact([Int64, Int64]), Exact([Float64, Float64])]) failed.
   ```
   ```
   [AFTER]DataFusion CLI v25.0.0
   ❯ select concat();
   Error during planning: No function matches the given name and argument types 
'concat()'. You might need to add explicit type casts.
           Candidate functions:
           concat(Utf8, ..)
   ❯ SELECT nullif(1);
   Error during planning: No function matches the given name and argument types 
'nullif(Int64)'. You might need to add explicit type casts.
           Candidate functions:
           
nullif(Boolean/UInt8/UInt16/UInt32/UInt64/Int8/Int16/Int32/Int64/Float32/Float64/Utf8/LargeUtf8,
 
Boolean/UInt8/UInt16/UInt32/UInt64/Int8/Int16/Int32/Int64/Float32/Float64/Utf8/LargeUtf8)
   ❯ SELECT pi(3.14);
   Error during planning: No function matches the given name and argument types 
'pi(Float64)'. You might need to add explicit type casts.
           Candidate functions:
           pi()
   ❯ SELECT arrow_typeof(1, 1);
   Error during planning: No function matches the given name and argument types 
'arrowtypeof(Int64, Int64)'. You might need to add explicit type casts.
           Candidate functions:
           arrowtypeof(Any)
   ❯ SELECT power('1', '2');
   Error during planning: No function matches the given name and argument types 
'power(Utf8, Utf8)'. You might need to add explicit type casts.
           Candidate functions:
           power(Int64, Int64)
           power(Float64, Float64)
   
   ```
   
   # 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.
   -->
   1.  Add a `function_err.rs` to generate error messages by providing 
candidate function signatures if input function arguments are not valid.
   2. Before this change, if functions have wrong number of args or input args 
can't be coerced into valid signatures, it will return different error 
messages, now they'll all report the error in this way.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   3. 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)?
   -->
   There are 5 function signature types from [internal implementation 
](https://github.com/apache/arrow-datafusion/blob/dd3a003c1ca4e2109f33277d13f2b0b2fa500337/datafusion/expr/src/signature.rs#L41),
 remaining 2 of them are not used when defining built-in scalar functions.
   1 of each signature type has an end-to-end sqllogictest for the error 
message.
   
   # 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to