Repository: spark
Updated Branches:
  refs/heads/branch-1.5 cbc6aecfc -> 8836ac3d1


[SPARK-10904] [SPARKR] Fix to support `select(df, c("col1", "col2"))`

The fix is to coerce `c("a", "b")` into a list such that it could be serialized 
to call JVM with.

Author: felixcheung <[email protected]>

Closes #8961 from felixcheung/rselect.

(cherry picked from commit 721e8b5f35b230ff426c1757a9bdc1399fb19afa)
Signed-off-by: Shivaram Venkataraman <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/8836ac3d
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/8836ac3d
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/8836ac3d

Branch: refs/heads/branch-1.5
Commit: 8836ac3d144a1755d796615c75676285adc104cd
Parents: cbc6aec
Author: felixcheung <[email protected]>
Authored: Sat Oct 3 22:42:36 2015 -0700
Committer: Shivaram Venkataraman <[email protected]>
Committed: Sat Oct 3 22:48:43 2015 -0700

----------------------------------------------------------------------
 R/pkg/R/DataFrame.R              | 14 +++++++++++---
 R/pkg/inst/tests/test_sparkSQL.R |  7 +++++++
 2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/8836ac3d/R/pkg/R/DataFrame.R
----------------------------------------------------------------------
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index f833e70..ed304c2 100644
--- a/R/pkg/R/DataFrame.R
+++ b/R/pkg/R/DataFrame.R
@@ -1044,12 +1044,20 @@ setMethod("subset", signature(x = "DataFrame"),
 #'   select(df, c("col1", "col2"))
 #'   select(df, list(df$name, df$age + 1))
 #'   # Similar to R data frames columns can also be selected using `$`
-#'   df$age
+#'   df[,df$age]
 #' }
 setMethod("select", signature(x = "DataFrame", col = "character"),
           function(x, col, ...) {
-            sdf <- callJMethod(x@sdf, "select", col, toSeq(...))
-            dataFrame(sdf)
+            if (length(col) > 1) {
+              if (length(list(...)) > 0) {
+                stop("To select multiple columns, use a character vector or 
list for col")
+              }
+
+              select(x, as.list(col))
+            } else {
+              sdf <- callJMethod(x@sdf, "select", col, toSeq(...))
+              dataFrame(sdf)
+            }
           })
 
 #' @rdname select

http://git-wip-us.apache.org/repos/asf/spark/blob/8836ac3d/R/pkg/inst/tests/test_sparkSQL.R
----------------------------------------------------------------------
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index 2062bc7..aedc385 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -585,6 +585,13 @@ test_that("select with column", {
   expect_equal(columns(df3), c("x"))
   expect_equal(count(df3), 3)
   expect_equal(collect(select(df3, "x"))[[1, 1]], "x")
+
+  df4 <- select(df, c("name", "age"))
+  expect_equal(columns(df4), c("name", "age"))
+  expect_equal(count(df4), 3)
+
+  expect_error(select(df, c("name", "age"), "name"),
+                "To select multiple columns, use a character vector or list 
for col")
 })
 
 test_that("subsetting", {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to