GitHub user gatorsmile opened a pull request:

    https://github.com/apache/spark/pull/18574

    [SPARK-21350] [SQL] Fix the error message when the number of arguments is 
wrong when invoking a UDF

    ### What changes were proposed in this pull request?
    Users get a very confusing error when users specify a wrong number of 
parameters. 
    ```Scala
        val df = spark.emptyDataFrame
        spark.udf.register("foo", (_: String).length)
        df.selectExpr("foo(2, 3, 4)")
    ```
    ```
    org.apache.spark.sql.UDFSuite$$anonfun$9$$anonfun$apply$mcV$sp$12 cannot be 
cast to scala.Function3
    java.lang.ClassCastException: 
org.apache.spark.sql.UDFSuite$$anonfun$9$$anonfun$apply$mcV$sp$12 cannot be 
cast to scala.Function3
        at 
org.apache.spark.sql.catalyst.expressions.ScalaUDF.<init>(ScalaUDF.scala:109)
    ```
    
    This PR is to capture the exception and issue an error message that is 
consistent with what we did for built-in functions. After the fix, the error 
message is improved to 
    ```
    Invalid number of arguments for function foo; line 1 pos 0
    org.apache.spark.sql.AnalysisException: Invalid number of arguments for 
function foo; line 1 pos 0
        at 
org.apache.spark.sql.catalyst.analysis.SimpleFunctionRegistry.lookupFunction(FunctionRegistry.scala:119)
    ```
    
    ### How was this patch tested?
    Added a test case

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gatorsmile/spark statsCheck

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/18574.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #18574
    
----
commit 8302c2a11efa1f444c2b69999fcc94ee4356d2ea
Author: gatorsmile <[email protected]>
Date:   2017-07-09T03:46:32Z

    fix.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to