spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Black...@b3k.us>
Subject Re: closures & moving averages (state)
Date Wed, 26 Mar 2014 15:49:40 GMT
Perhaps you want reduce rather than map?

On Wednesday, March 26, 2014, Adrian Mocanu <amocanu@verticalscope.com>
wrote:

>  I'm passing a moving average function during the map phase like this:
>
>   val average= new Sma(window=3)
>
> stream.map(x=> average.addNumber(x))
>
>
>
> where
>
>   class Sma extends Serializable { .. }
>
>
>
> I also tried to put creation of object average in an object like I saw in
> another post:
>
>  object Average {
>
>     val smaFn = new VSRTXYSimpleMovingAverage[(String, Long)](3)
>
>  }
>
>  Every time  average.addNumber is called it is a new instance.
>
> How can I preserve state of average object?
>
>
>
> Thanks
>
> -Adrian
>
>
>

Mime
View raw message