aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/inst/tests/test_sparkSQL.R
diff options
context:
space:
mode:
authorfelixcheung <felixcheung_m@hotmail.com>2015-08-25 23:48:16 -0700
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2015-08-25 23:48:16 -0700
commit75d4773aa50e24972c533e8b48697fde586429eb (patch)
tree45339e6875e2d5c2f3ff0375f24c75516b94e159 /R/pkg/inst/tests/test_sparkSQL.R
parent321d7759691bed9867b1f0470f12eab2faa50aff (diff)
downloadspark-75d4773aa50e24972c533e8b48697fde586429eb.tar.gz
spark-75d4773aa50e24972c533e8b48697fde586429eb.tar.bz2
spark-75d4773aa50e24972c533e8b48697fde586429eb.zip
[SPARK-9316] [SPARKR] Add support for filtering using `[` (synonym for filter / select)
Add support for ``` df[df$name == "Smith", c(1,2)] df[df$age %in% c(19, 30), 1:2] ``` shivaram Author: felixcheung <felixcheung_m@hotmail.com> Closes #8394 from felixcheung/rsubset.
Diffstat (limited to 'R/pkg/inst/tests/test_sparkSQL.R')
-rw-r--r--R/pkg/inst/tests/test_sparkSQL.R27
1 files changed, 27 insertions, 0 deletions
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index 556b8c5447..ee48a3dc0c 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -587,6 +587,33 @@ test_that("select with column", {
expect_equal(collect(select(df3, "x"))[[1, 1]], "x")
})
+test_that("subsetting", {
+ # jsonFile returns columns in random order
+ df <- select(jsonFile(sqlContext, jsonPath), "name", "age")
+ filtered <- df[df$age > 20,]
+ expect_equal(count(filtered), 1)
+ expect_equal(columns(filtered), c("name", "age"))
+ expect_equal(collect(filtered)$name, "Andy")
+
+ df2 <- df[df$age == 19, 1]
+ expect_is(df2, "DataFrame")
+ expect_equal(count(df2), 1)
+ expect_equal(columns(df2), c("name"))
+ expect_equal(collect(df2)$name, "Justin")
+
+ df3 <- df[df$age > 20, 2]
+ expect_equal(count(df3), 1)
+ expect_equal(columns(df3), c("age"))
+
+ df4 <- df[df$age %in% c(19, 30), 1:2]
+ expect_equal(count(df4), 2)
+ expect_equal(columns(df4), c("name", "age"))
+
+ df5 <- df[df$age %in% c(19), c(1,2)]
+ expect_equal(count(df5), 1)
+ expect_equal(columns(df5), c("name", "age"))
+})
+
test_that("selectExpr() on a DataFrame", {
df <- jsonFile(sqlContext, jsonPath)
selected <- selectExpr(df, "age * 2")