Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/main/scala/org/apache/spark/rdd/RDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ abstract class RDD[T: ClassTag](
preservesPartitioning = true)
}

/**
* Return a new RDD containing only the elements that satisfy a predicate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @reggert .
Could you fix the indentation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother unless we have consensus to introduce this API?

* This is an alias for filter so that RDDs can be used in for comprehensions without causing the
* compiler to complain.
*/
@inline
final def withFilter(f: T => Boolean): RDD[T] = filter(f)

/**
* Return a new RDD containing the distinct elements in this RDD.
*/
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class RDDSuite extends SparkFunSuite with SharedSparkContext {
assert(!nums.isEmpty())
assert(nums.max() === 4)
assert(nums.min() === 1)
assert((for (n <- nums if n > 2) yield n).collect().toList === List(3, 4))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this get compiled into?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to IntelliJ, the for comprehension desugars into

nums.withFilter(n => n > 2).map(n => n)

val partitionSums = nums.mapPartitions(iter => Iterator(iter.sum))
assert(partitionSums.collect().toList === List(3, 7))

Expand Down