aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests/testthat/test_sparkSQL.R
diff options
context:
space:
mode:
authorzero323 <zero323@users.noreply.github.com>2017-04-19 21:19:46 -0700
committerFelix Cheung <felixcheung@apache.org>2017-04-19 21:19:46 -0700
commit46c5749768fefd976097c7d5612ec184a4cfe1b9 (patch)
tree5e8ce2ee22d848cae449df228c50dfab61e85d34 /R/pkg/inst/tests/testthat/test_sparkSQL.R
parentbdc60569196e9ae4e9086c3e514a406a9e8b23a6 (diff)
downloadspark-46c5749768fefd976097c7d5612ec184a4cfe1b9.tar.gz
spark-46c5749768fefd976097c7d5612ec184a4cfe1b9.tar.bz2
spark-46c5749768fefd976097c7d5612ec184a4cfe1b9.zip
[SPARK-20375][R] R wrappers for array and map
## What changes were proposed in this pull request? Adds wrappers for `o.a.s.sql.functions.array` and `o.a.s.sql.functions.map` ## How was this patch tested? Unit tests, `check-cran.sh` Author: zero323 <zero323@users.noreply.github.com> Closes #17674 from zero323/SPARK-20375.
Diffstat (limited to 'R/pkg/inst/tests/testthat/test_sparkSQL.R')
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R17
1 files changed, 17 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index 6a6c9a809a..9e87a47106 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -1461,6 +1461,23 @@ test_that("column functions", {
expect_equal(length(arr$arrcol[[1]]), 2)
expect_equal(arr$arrcol[[1]][[1]]$name, "Bob")
expect_equal(arr$arrcol[[1]][[2]]$name, "Alice")
+
+ # Test create_array() and create_map()
+ df <- as.DataFrame(data.frame(
+ x = c(1.0, 2.0), y = c(-1.0, 3.0), z = c(-2.0, 5.0)
+ ))
+
+ arrs <- collect(select(df, create_array(df$x, df$y, df$z)))
+ expect_equal(arrs[, 1], list(list(1, -1, -2), list(2, 3, 5)))
+
+ maps <- collect(select(
+ df, create_map(lit("x"), df$x, lit("y"), df$y, lit("z"), df$z)))
+
+ expect_equal(
+ maps[, 1],
+ lapply(
+ list(list(x = 1, y = -1, z = -2), list(x = 2, y = 3, z = 5)),
+ as.environment))
})
test_that("column binary mathfunctions", {