spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Pfeiffer <...@preferred.jp>
Subject Re: How to run an action and get output?
Date Wed, 24 Dec 2014 02:52:03 GMT
Hi,

On Fri, Dec 19, 2014 at 6:53 PM, Ashic Mahtab <ashic@live.com> wrote:
>
> val doSomething(entry:SomeEntry, session:Session) : SomeOutput = {
>     val result = session.SomeOp(entry)
>     SomeOutput(entry.Key, result.SomeProp)
> }
>
> I could use a transformation for rdd.map, but in case of failures, the map
> would run on another executor for the same rdd. I could do rdd.foreach, but
> that returns unit. Is there something like a foreach that can return values?
>

I think `map()` is pretty much "`foreach()` that can return values". If you
want to prevent re-execution on errors, wrap the whole thing in a
scala.util.Try{} block or something.

rdd.map(item => {
  Try{ ... }
}).flatMap(_ match {
  case Success(something) => Some(something)
  case Failure(e) => None
})

or so.

Tobias

Mime
View raw message