You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Deborah Siegel (JIRA)" <ji...@apache.org> on 2016/01/29 01:31:39 UTC

[jira] [Commented] (SPARK-12526) `ifelse`, `when`, `otherwise` unable to take Column as value

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

Deborah Siegel commented on SPARK-12526:
----------------------------------------

I'm trying to use ifelse (or when and otherwise) to replace some of the values in a column (or create a new column which uses the old column for some of its values). I believe this falls into the case of wanting to do the above example
>ifelse(df$mpg > 0, df$mpg, 0)

Here's my example:
aq$mynewcolumn <- ifelse(aq$Ozone != "NA", aq$Ozone, "<NA>")
or
aq$mynewcolumn <- otherwise(when(aq$Ozone == "NA", "<NA>"), aq$Ozone)

Is it correct that this still won't work in 1.6.0 with: 
Error in rep(yes, length.out = length(ans)) : 
  attempt to replicate an object of type 'environment'


> `ifelse`, `when`, `otherwise` unable to take Column as value
> ------------------------------------------------------------
>
>                 Key: SPARK-12526
>                 URL: https://issues.apache.org/jira/browse/SPARK-12526
>             Project: Spark
>          Issue Type: Bug
>          Components: SparkR
>    Affects Versions: 1.5.2, 1.6.0
>            Reporter: Sen Fang
>            Assignee: Sen Fang
>             Fix For: 1.6.1, 2.0.0
>
>
> When passing a Column to {{ifelse}}, {{when}}, {{otherwise}}, it will error out with
> {code}
> attempt to replicate an object of type 'environment'
> {code}
> The problems lies in the use of base R {{ifelse}} function, which is vectorized version of {{if ... else ...}} idiom, but it is unable to replicate a Column's job id as it is an environment.
> Considering {{callJMethod}} was never designed to be vectorized, the safe option is to replace {{ifelse}} with {{if ... else ...}} instead. However technically this is inconsistent to base R's ifelse, which is meant to be vectorized.
> I can send a PR for review first and discuss further if there is scenario at all when `ifelse`, `when`, `otherwise` would be used vectorizedly.
> A dummy example is:
> {code}
> ifelse(lit(1) == lit(1), lit(2), lit(3))
> {code}
> A concrete example might be:
> {code}
> ifelse(df$mpg > 0, df$mpg, 0)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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