aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests
diff options
context:
space:
mode:
authorFelix Cheung <felixcheung_m@hotmail.com>2017-01-11 08:29:09 -0800
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2017-01-11 08:29:09 -0800
commitd749c06677c2fd383733337f1c00f542da122b8d (patch)
tree775d6750789d1a76988bca912de0b1bca8bb7ef4 /R/pkg/inst/tests
parent4239a1081ad96a503fbf9277e42b97422bb8af3e (diff)
downloadspark-d749c06677c2fd383733337f1c00f542da122b8d.tar.gz
spark-d749c06677c2fd383733337f1c00f542da122b8d.tar.bz2
spark-d749c06677c2fd383733337f1c00f542da122b8d.zip
[SPARK-19130][SPARKR] Support setting literal value as column implicitly
## What changes were proposed in this pull request? ``` df$foo <- 1 ``` instead of ``` df$foo <- lit(1) ``` ## How was this patch tested? unit tests Author: Felix Cheung <felixcheung_m@hotmail.com> Closes #16510 from felixcheung/rlitcol.
Diffstat (limited to 'R/pkg/inst/tests')
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R18
1 files changed, 18 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index c3f0310c75..3e8b96a513 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -1001,6 +1001,17 @@ test_that("select operators", {
expect_equal(columns(df), c("name", "age", "age2"))
expect_equal(count(where(df, df$age2 == df$age * 2)), 2)
+ df$age2 <- 21
+ expect_equal(columns(df), c("name", "age", "age2"))
+ expect_equal(count(where(df, df$age2 == 21)), 3)
+
+ df$age2 <- c(22)
+ expect_equal(columns(df), c("name", "age", "age2"))
+ expect_equal(count(where(df, df$age2 == 22)), 3)
+
+ expect_error(df$age3 <- c(22, NA),
+ "value must be a Column, literal value as atomic in length of 1, or NULL")
+
# Test parameter drop
expect_equal(class(df[, 1]) == "SparkDataFrame", T)
expect_equal(class(df[, 1, drop = T]) == "Column", T)
@@ -1778,6 +1789,13 @@ test_that("withColumn() and withColumnRenamed()", {
expect_equal(length(columns(newDF)), 2)
expect_equal(first(filter(newDF, df$name != "Michael"))$age, 32)
+ newDF <- withColumn(df, "age", 18)
+ expect_equal(length(columns(newDF)), 2)
+ expect_equal(first(newDF)$age, 18)
+
+ expect_error(withColumn(df, "age", list("a")),
+ "Literal value must be atomic in length of 1")
+
newDF2 <- withColumnRenamed(df, "age", "newerAge")
expect_equal(length(columns(newDF2)), 2)
expect_equal(columns(newDF2)[1], "newerAge")