Skip to content

Commit

Permalink
[SPARK-8431][SparkR] Add in operator to DataFrame Column in SparkR
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-iskw committed Jun 22, 2015
1 parent b1f3a48 commit c196173
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R/pkg/R/column.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ createOperator <- function(op) {
})
}

createInOperator <- function(op) {
setMethod("%in%",
signature(x = "Column"),
function(x, table) {
table <- listToSeq(as.list(table))
bar <- callJMethod(x@jc, "in", table)
return(column(bar))
})
}

createColumnFunction1 <- function(name) {
setMethod(name,
signature(x = "Column"),
Expand Down Expand Up @@ -139,6 +149,7 @@ createBinaryMathfunctions <- function(name) {
}

createMethods <- function() {
createInOperator()
for (op in names(operators)) {
createOperator(op)
}
Expand Down
10 changes: 10 additions & 0 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit c196173

Please sign in to comment.