You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Apache Spark (JIRA)" <ji...@apache.org> on 2018/01/02 03:39:00 UTC

[jira] [Commented] (SPARK-19165) UserDefinedFunction should verify call arguments and provide readable exception in case of mismatch

    [ https://issues.apache.org/jira/browse/SPARK-19165?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16307649#comment-16307649 ] 

Apache Spark commented on SPARK-19165:
--------------------------------------

User 'HyukjinKwon' has created a pull request for this issue:
https://github.com/apache/spark/pull/19027

> UserDefinedFunction should verify call arguments and provide readable exception in case of mismatch
> ---------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-19165
>                 URL: https://issues.apache.org/jira/browse/SPARK-19165
>             Project: Spark
>          Issue Type: Sub-task
>          Components: PySpark, SQL
>    Affects Versions: 1.6.0, 2.0.0, 2.1.0, 2.2.0
>            Reporter: Maciej Szymkiewicz
>            Assignee: Hyukjin Kwon
>            Priority: Minor
>             Fix For: 2.3.0
>
>
> Invalid arguments to UDF call fail with a bit cryptic Py4J errors:
> {code}
> In [5]: g = udf(lambda x: x)
> In [6]: df.select(f([]))
> ---------------------------------------------------------------------------
> Py4JError                                 Traceback (most recent call last)
> <ipython-input-10-5fb48a5d66d2> in <module>()
> ----> 1 df.select(f([]))
> ....
> Py4JError: An error occurred while calling z:org.apache.spark.sql.functions.col. Trace:
> py4j.Py4JException: Method col([class java.util.ArrayList]) does not exist
> 	at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
> 	at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:339)
> 	at py4j.Gateway.invoke(Gateway.java:274)
> 	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
> 	at py4j.commands.CallCommand.execute(CallCommand.java:79)
> 	at py4j.GatewayConnection.run(GatewayConnection.java:214)
> 	at java.lang.Thread.run(Thread.java:745)
> {code}
> It is pretty easy to perform basic input validation:
> {code}
> In [8]: f = udf(lambda x: x)
> In [9]: f(1)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> ...
> TypeError: All arguments should be Columns or strings representing column names. Got 1 of type <class 'int'>
> {code}
> This can be further extended to check for expected number of arguments or even, with some type of annotations, SQL types.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org