aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests/testthat/test_sparkSQL.R
diff options
context:
space:
mode:
authorHossein <hossein@databricks.com>2016-10-21 12:38:52 -0700
committerFelix Cheung <felixcheung@apache.org>2016-10-21 12:38:52 -0700
commite371040a0150e4ed748a7c25465965840b61ca63 (patch)
tree3ec1992dfbb0487b318daf425cfa10229a02c99b /R/pkg/inst/tests/testthat/test_sparkSQL.R
parente21e1c946c4b7448fb150cfa2d9419864ae6f9b5 (diff)
downloadspark-e371040a0150e4ed748a7c25465965840b61ca63.tar.gz
spark-e371040a0150e4ed748a7c25465965840b61ca63.tar.bz2
spark-e371040a0150e4ed748a7c25465965840b61ca63.zip
[SPARK-17811] SparkR cannot parallelize data.frame with NA or NULL in Date columns
## What changes were proposed in this pull request? NA date values are serialized as "NA" and NA time values are serialized as NaN from R. In the backend we did not have proper logic to deal with them. As a result we got an IllegalArgumentException for Date and wrong value for time. This PR adds support for deserializing NA as Date and Time. ## How was this patch tested? * [x] TODO Author: Hossein <hossein@databricks.com> Closes #15421 from falaki/SPARK-17811.
Diffstat (limited to 'R/pkg/inst/tests/testthat/test_sparkSQL.R')
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R13
1 files changed, 13 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index 3a987cd862..b4b43fdba4 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -390,6 +390,19 @@ test_that("create DataFrame with different data types", {
expect_equal(collect(df), data.frame(l, stringsAsFactors = FALSE))
})
+test_that("SPARK-17811: can create DataFrame containing NA as date and time", {
+ df <- data.frame(
+ id = 1:2,
+ time = c(as.POSIXlt("2016-01-10"), NA),
+ date = c(as.Date("2016-10-01"), NA))
+
+ DF <- collect(createDataFrame(df))
+ expect_true(is.na(DF$date[2]))
+ expect_equal(DF$date[1], as.Date("2016-10-01"))
+ expect_true(is.na(DF$time[2]))
+ expect_equal(DF$time[1], as.POSIXlt("2016-01-10"))
+})
+
test_that("create DataFrame with complex types", {
e <- new.env()
assign("n", 3L, envir = e)