Skip to content

Commit

Permalink
Merge pull request apache#192 from cafreeman/sparkr-sql
Browse files Browse the repository at this point in the history
define generic for 'first' in RDD API
  • Loading branch information
shivaram committed Mar 3, 2015
2 parents eb8ac11 + 1955a09 commit 76cf2e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exportMethods(
"distinct",
"Filter",
"filterRDD",
"first",
"flatMap",
"flatMapValues",
"fold",
Expand Down Expand Up @@ -87,7 +88,6 @@ exportClasses("DataFrame")
exportMethods("columns",
"distinct",
"dtypes",
"first",
"head",
"limit",
"names",
Expand Down
2 changes: 0 additions & 2 deletions pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ setMethod("head",
#' first(df)
#' }

setGeneric("first", function(x) {standardGeneric("first") })

setMethod("first",
signature(x = "DataFrame"),
function(x) {
Expand Down
20 changes: 20 additions & 0 deletions pkg/R/RDD.R
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,26 @@ setMethod("take",
resList
})

#' First
#'
#' Return the first element of an RDD
#'
#' @rdname first
#' @export
#' @examples
#'\dontrun{
#' sc <- sparkR.init()
#' rdd <- parallelize(sc, 1:10)
#' first(rdd)
#' }
setGeneric("first", function(x) { standardGeneric("first") })

setMethod("first",
signature(x = "RDD"),
function(x) {
take(x, 1)[[1]]
})

#' Removes the duplicates from RDD.
#'
#' This function returns a new RDD containing the distinct elements in the
Expand Down
6 changes: 6 additions & 0 deletions pkg/inst/tests/test_rdd.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ test_that("get number of partitions in RDD", {
expect_equal(numPartitions(intRdd), 2)
})

test_that("first on RDD", {
expect_true(first(rdd) == 1)
newrdd <- lapply(rdd, function(x) x + 1)
expect_true(first(newrdd) == 2)
})

test_that("count and length on RDD", {
expect_equal(count(rdd), 10)
expect_equal(length(rdd), 10)
Expand Down

0 comments on commit 76cf2e0

Please sign in to comment.