riccardo.cardin riccardo.cardin - 2 months ago 10
Scala Question

Getting an RDD of Failure[T] from an RDD[Try[T]] without compilation warning

I have an

RDD[Try[T]]
and I want to trasnf
RDD
that contains only the element of type
Failure[T]
, which means all the element for which the method
isFailure
returns
true
. By now, I found the following solution.

rows.filter(row => row.isFailure)
.map {
case Failure(e) => // Do something...
}


Warning:(11, 36) match may not be exhaustive.
It would fail on the following input: Success(_)
map {


Is there any method to obtain the same result without incurring in the compilation warning?

Thanks a lot.

Answer

At the first glance it looks like collect would be a better fit here:

rows.collect {
  case f @ Failure(e) => f
}
Comments