Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-20 Thread Victor Tso-Guillen
And duh, of course, you can do the setup in that new RDD as well :) On Wed, Aug 20, 2014 at 1:59 AM, Victor Tso-Guillen wrote: > How about this: > > val prev: RDD[V] = rdd.mapPartitions(partition => { /*setup()*/; partition > }) > new RDD[V](prev) { > protected def getPartitions = prev.partit

Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-20 Thread Victor Tso-Guillen
How about this: val prev: RDD[V] = rdd.mapPartitions(partition => { /*setup()*/; partition }) new RDD[V](prev) { protected def getPartitions = prev.partitions def compute(split: Partition, context: TaskContext) = { context.addOnCompleteCallback(() => /*cleanup()*/) firstParent[V].iter

Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-19 Thread Sean Owen
I think you're looking for foreachPartition(). You've kinda hacked it out of mapPartitions(). Your case has a simple solution, yes. After saving to the DB, you know you can close the connection, since you know the use of the connection has definitely just finished. But it's not a simpler solution f

Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-19 Thread Yana Kadiyska
> > > > > > > > http://mail-archives.apache.org/mod_mbox/spark-user/201404.mbox/%3CCAF > > _KkPzpU4qZWzDWUpS5r9bbh=-hwnze2qqg56e25p--1wv...@mail.gmail.com%3E > > > > > > > > Best regards, > > > > Henry > > > > > > >

RE: a noob question for how to implement setup and cleanup in Spark map

2014-08-18 Thread Henry Hung
@spark.apache.org Subject: Re: a noob question for how to implement setup and cleanup in Spark map I think this was a more comprehensive answer recently. Tobias is right that it is not quite that simple: http://mail-archives.apache.org/mod_mbox/spark-user/201407.mbox/%3CCAPH-c_O9kQO6yJ4khXUVdO

Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-18 Thread Sean Owen
ards, > > Henry > > > > From: MA33 YTHung1 > Sent: Monday, August 18, 2014 2:42 PM > To: user@spark.apache.org > Subject: a noob question for how to implement setup and cleanup in Spark map > > > > Hi All, > > > > I’m new to Spark and Scala, just r

Re: a noob question for how to implement setup and cleanup in Spark map

2014-08-18 Thread Akhil Das
gt; > Henry > > > > *From:* MA33 YTHung1 > *Sent:* Monday, August 18, 2014 2:42 PM > *To:* user@spark.apache.org > *Subject:* a noob question for how to implement setup and cleanup in > Spark map > > > > Hi All, > > > > I’m new to Spark and Scala,

RE: a noob question for how to implement setup and cleanup in Spark map

2014-08-18 Thread Henry Hung
2:42 PM To: user@spark.apache.org Subject: a noob question for how to implement setup and cleanup in Spark map Hi All, I'm new to Spark and Scala, just recently using this language and love it, but there is a small coding problem when I want to convert my existing map reduce code from Ja

a noob question for how to implement setup and cleanup in Spark map

2014-08-17 Thread Henry Hung
Hi All, I'm new to Spark and Scala, just recently using this language and love it, but there is a small coding problem when I want to convert my existing map reduce code from Java to Spark... In Java, I create a class by extending org.apache.hadoop.mapreduce.Mapper and override the setup(), ma