Skip to content

Commit 08e24c3

Browse files
Merge pull request apache#109 from hlin09/hlin09
[SPARKR-15] Rename the filter function to filterRDD to follow the API consistency.
2 parents 4dca9b1 + bb779bf commit 08e24c3

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

pkg/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exportMethods(
1313
"countByValue",
1414
"distinct",
1515
"Filter",
16-
"filter",
16+
"filterRDD",
1717
"flatMap",
1818
"flatMapValues",
1919
"groupByKey",

pkg/R/RDD.R

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -600,39 +600,36 @@ setMethod("mapPartitionsWithIndex",
600600
#' a predicate (i.e. returning TRUE in a given logical function).
601601
#' The same as `filter()' in Spark.
602602
#'
603-
#' @param f A unary predicate function.
604-
#' @param x The RDD to be filtered.
605-
#' @rdname Filter
603+
#' @param rdd The RDD to be filtered.
604+
#' @param filterFunc A unary predicate function.
605+
#' @rdname filterRDD
606606
#' @export
607607
#' @examples
608608
#'\dontrun{
609609
#' sc <- sparkR.init()
610610
#' rdd <- parallelize(sc, 1:10)
611-
#' unlist(collect(Filter(function (x) { x < 3 }, rdd))) # c(1, 2)
611+
#' unlist(collect(filterRDD(rdd, function (x) { x < 3 }))) # c(1, 2)
612612
#'}
613-
#setGeneric("Filter", function(f, x) { standardGeneric("Filter") })
614-
615-
#' @rdname Filter
616-
#' @aliases Filter,function,RDD-method filter,function,RDD-method
617-
setMethod("Filter",
618-
signature(f = "function", x = "RDD"),
619-
function(f, x) {
613+
setGeneric("filterRDD",
614+
function(rdd, filterFunc) { standardGeneric("filterRDD") })
615+
616+
#' @rdname filterRDD
617+
#' @aliases filterRDD,RDD,function-method
618+
setMethod("filterRDD",
619+
signature(rdd = "RDD", filterFunc = "function"),
620+
function(rdd, filterFunc) {
620621
filter.func <- function(part) {
621-
Filter(f, part)
622+
Filter(filterFunc, part)
622623
}
623-
lapplyPartition(x, filter.func)
624+
lapplyPartition(rdd, filter.func)
624625
})
625626

626-
#' @rdname Filter
627-
#' @export
628-
setGeneric("filter", function(f, x) { standardGeneric("filter") })
629-
630-
#' @rdname Filter
631-
#' @aliases filter,function,RDD-method
632-
setMethod("filter",
627+
#' @rdname filterRDD
628+
#' @aliases Filter,function,RDD-method
629+
setMethod("Filter",
633630
signature(f = "function", x = "RDD"),
634631
function(f, x) {
635-
Filter(f, x)
632+
filterRDD(x, f)
636633
})
637634

638635
#' Reduce across elements of an RDD.

pkg/inst/tests/test_rdd.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ test_that("flatMap() on RDDs", {
5555
expect_equal(actual, rep(intPairs, each=2))
5656
})
5757

58-
test_that("Filter on RDD", {
59-
filtered.rdd <- Filter(function(x) { x %% 2 == 0 }, rdd)
58+
test_that("filterRDD on RDD", {
59+
filtered.rdd <- filterRDD(rdd, function(x) { x %% 2 == 0 })
6060
actual <- collect(filtered.rdd)
6161
expect_equal(actual, list(2, 4, 6, 8, 10))
6262

@@ -65,7 +65,7 @@ test_that("Filter on RDD", {
6565
expect_equal(actual, list(list(1L, -1)))
6666

6767
# Filter out all elements.
68-
filtered.rdd <- Filter(function(x) { x > 10 }, rdd)
68+
filtered.rdd <- filterRDD(rdd, function(x) { x > 10 })
6969
actual <- collect(filtered.rdd)
7070
expect_equal(actual, list())
7171
})
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
% Generated by roxygen2 (4.0.2): do not edit by hand
22
\docType{methods}
3-
\name{Filter,function,RDD-method}
3+
\name{filterRDD}
44
\alias{Filter,function,RDD-method}
5-
\alias{filter}
6-
\alias{filter,function,RDD-method}
5+
\alias{filterRDD}
6+
\alias{filterRDD,RDD,function-method}
77
\title{This function returns a new RDD containing only the elements that satisfy
88
a predicate (i.e. returning TRUE in a given logical function).
99
The same as `filter()' in Spark.}
1010
\usage{
11-
\S4method{Filter}{`function`,RDD}(f, x)
11+
filterRDD(rdd, filterFunc)
1212
13-
filter(f, x)
13+
\S4method{filterRDD}{RDD,`function`}(rdd, filterFunc)
1414
15-
\S4method{filter}{`function`,RDD}(f, x)
15+
\S4method{Filter}{`function`,RDD}(f, x)
1616
}
1717
\arguments{
18-
\item{f}{A unary predicate function.}
18+
\item{rdd}{The RDD to be filtered.}
1919
20-
\item{x}{The RDD to be filtered.}
20+
\item{filterFunc}{A unary predicate function.}
2121
}
2222
\description{
2323
This function returns a new RDD containing only the elements that satisfy
@@ -28,7 +28,7 @@ The same as `filter()' in Spark.
2828
\dontrun{
2929
sc <- sparkR.init()
3030
rdd <- parallelize(sc, 1:10)
31-
unlist(collect(Filter(function (x) { x < 3 }, rdd))) # c(1, 2)
31+
unlist(collect(filterRDD(rdd, function (x) { x < 3 }))) # c(1, 2)
3232
}
3333
}
3434

0 commit comments

Comments
 (0)