diff options
author | Yu ISHIKAWA <yuu.ishikawa@gmail.com> | 2015-08-18 20:27:36 -0700 |
---|---|---|
committer | Shivaram Venkataraman <shivaram@cs.berkeley.edu> | 2015-08-18 20:27:36 -0700 |
commit | bf32c1f7f47dd907d787469f979c5859e02ce5e6 (patch) | |
tree | b6ff3e44b631be5eb60e1f0d1850b019b0c1b2b4 /R/pkg/inst/tests/test_sparkSQL.R | |
parent | a5b5b936596ceb45f5f5b68bf1d6368534fb9470 (diff) | |
download | spark-bf32c1f7f47dd907d787469f979c5859e02ce5e6.tar.gz spark-bf32c1f7f47dd907d787469f979c5859e02ce5e6.tar.bz2 spark-bf32c1f7f47dd907d787469f979c5859e02ce5e6.zip |
[SPARK-10075] [SPARKR] Add `when` expressino function in SparkR
- Add `when` and `otherwise` as `Column` methods
- Add `When` as an expression function
- Add `%otherwise%` infix as an alias of `otherwise`
Since R doesn't support a feature like method chaining, `otherwise(when(condition, value), value)` style is a little annoying for me. If `%otherwise%` looks strange for shivaram, I can remove it. What do you think?
### JIRA
[[SPARK-10075] Add `when` expressino function in SparkR - ASF JIRA](https://issues.apache.org/jira/browse/SPARK-10075)
Author: Yu ISHIKAWA <yuu.ishikawa@gmail.com>
Closes #8266 from yu-iskw/SPARK-10075.
Diffstat (limited to 'R/pkg/inst/tests/test_sparkSQL.R')
-rw-r--r-- | R/pkg/inst/tests/test_sparkSQL.R | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R index 83caba8b5b..841de657df 100644 --- a/R/pkg/inst/tests/test_sparkSQL.R +++ b/R/pkg/inst/tests/test_sparkSQL.R @@ -727,6 +727,13 @@ test_that("greatest() and least() on a DataFrame", { expect_equal(collect(select(df, least(df$a, df$b)))[, 1], c(1, 3)) }) +test_that("when() and otherwise() on a DataFrame", { + l <- list(list(a = 1, b = 2), list(a = 3, b = 4)) + df <- createDataFrame(sqlContext, l) + expect_equal(collect(select(df, when(df$a > 1 & df$b > 2, 1)))[, 1], c(NA, 1)) + expect_equal(collect(select(df, otherwise(when(df$a > 1, 1), 0)))[, 1], c(0, 1)) +}) + test_that("group by", { df <- jsonFile(sqlContext, jsonPath) df1 <- agg(df, name = "max", age = "sum") |