You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Nicolas Porter (JIRA)" <ji...@apache.org> on 2017/10/25 00:54:00 UTC
[jira] [Updated] (SPARK-22347) UDF is evaluated when 'F.when'
condition is false
[ https://issues.apache.org/jira/browse/SPARK-22347?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nicolas Porter updated SPARK-22347:
-----------------------------------
Description:
Here's a simple example on how to reproduce this:
{code}
from pyspark.sql import functions as F, Row, types
def Divide10():
def fn(value): return 10 / int(value)
return F.udf(fn, types.IntegerType())
df = sc.parallelize([Row(x=5), Row(x=0)]).toDF()
x = F.col('x')
df2 = df.select(F.when((x > 0), Divide10()(x)))
df2.show(200)
{code}
This raises a division by zero error, even if `F.when` is trying to filter out all cases where `x <= 0`. I believe the correct behavior should be not to evaluate the UDF since the condition fails.
was:
Here's a simple example on how to reproduce this:
{code}
from pyspark.sql import functions as F, Row, types
def Divide10():
def fn(value): return 10 / int(value)
return F.udf(fn, types.IntegerType())
df = sc.parallelize([Row(x=5), Row(x=0)]).toDF()
x = F.col('x')
df2 = df.select(F.when((x > 0), Divide10()(x)))
df2.show(200)
{code}
This raises a division by zero error, even if `F.when` is trying to filter out all cases where `x <= 0`. I believe the correct behavior should be not to evaluate the UDF since the condition fails.
> UDF is evaluated when 'F.when' condition is false
> -------------------------------------------------
>
> Key: SPARK-22347
> URL: https://issues.apache.org/jira/browse/SPARK-22347
> Project: Spark
> Issue Type: Bug
> Components: PySpark
> Affects Versions: 2.2.0
> Reporter: Nicolas Porter
> Priority: Minor
>
> Here's a simple example on how to reproduce this:
> {code}
> from pyspark.sql import functions as F, Row, types
> def Divide10():
> def fn(value): return 10 / int(value)
> return F.udf(fn, types.IntegerType())
> df = sc.parallelize([Row(x=5), Row(x=0)]).toDF()
> x = F.col('x')
> df2 = df.select(F.when((x > 0), Divide10()(x)))
> df2.show(200)
> {code}
> This raises a division by zero error, even if `F.when` is trying to filter out all cases where `x <= 0`. I believe the correct behavior should be not to evaluate the UDF since the condition fails.
--
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