diff options
author | Yu ISHIKAWA <yuu.ishikawa@gmail.com> | 2015-06-22 23:04:36 -0700 |
---|---|---|
committer | Davies Liu <davies@databricks.com> | 2015-06-22 23:04:36 -0700 |
commit | d4f633514a393320c9ae64c00a75f702e6f58c67 (patch) | |
tree | b3df8e57ccaecaf4d3a784e48a19008ecb0840fb /R | |
parent | 164fe2aa44993da6c77af6de5efdae47a8b3958c (diff) | |
download | spark-d4f633514a393320c9ae64c00a75f702e6f58c67.tar.gz spark-d4f633514a393320c9ae64c00a75f702e6f58c67.tar.bz2 spark-d4f633514a393320c9ae64c00a75f702e6f58c67.zip |
[SPARK-8431] [SPARKR] Add in operator to DataFrame Column in SparkR
[[SPARK-8431] Add in operator to DataFrame Column in SparkR - ASF JIRA](https://issues.apache.org/jira/browse/SPARK-8431)
Author: Yu ISHIKAWA <yuu.ishikawa@gmail.com>
Closes #6941 from yu-iskw/SPARK-8431 and squashes the following commits:
1f64423 [Yu ISHIKAWA] Modify the comment
f4309a7 [Yu ISHIKAWA] Make a `setMethod` for `%in%` be independent
6e37936 [Yu ISHIKAWA] Modify a variable name
c196173 [Yu ISHIKAWA] [SPARK-8431][SparkR] Add in operator to DataFrame Column in SparkR
Diffstat (limited to 'R')
-rw-r--r-- | R/pkg/R/column.R | 16 | ||||
-rw-r--r-- | R/pkg/inst/tests/test_sparkSQL.R | 10 |
2 files changed, 26 insertions, 0 deletions
diff --git a/R/pkg/R/column.R b/R/pkg/R/column.R index 80e92d3105..8e4b0f5bf1 100644 --- a/R/pkg/R/column.R +++ b/R/pkg/R/column.R @@ -210,6 +210,22 @@ setMethod("cast", } }) +#' Match a column with given values. +#' +#' @rdname column +#' @return a matched values as a result of comparing with given values. +#' \dontrun{ +#' filter(df, "age in (10, 30)") +#' where(df, df$age %in% c(10, 30)) +#' } +setMethod("%in%", + signature(x = "Column"), + function(x, table) { + table <- listToSeq(as.list(table)) + jc <- callJMethod(x@jc, "in", table) + return(column(jc)) + }) + #' Approx Count Distinct #' #' @rdname column diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R index fc7f3f074b..417153dc09 100644 --- a/R/pkg/inst/tests/test_sparkSQL.R +++ b/R/pkg/inst/tests/test_sparkSQL.R @@ -693,6 +693,16 @@ test_that("filter() on a DataFrame", { filtered2 <- where(df, df$name != "Michael") expect_true(count(filtered2) == 2) expect_true(collect(filtered2)$age[2] == 19) + + # test suites for %in% + filtered3 <- filter(df, "age in (19)") + expect_equal(count(filtered3), 1) + filtered4 <- filter(df, "age in (19, 30)") + expect_equal(count(filtered4), 2) + filtered5 <- where(df, df$age %in% c(19)) + expect_equal(count(filtered5), 1) + filtered6 <- where(df, df$age %in% c(19, 30)) + expect_equal(count(filtered6), 2) }) test_that("join() on a DataFrame", { |