I don't think your question is very clear -- *updateStateByKey* usually updates the previous state.
For example, the StatefulNetworkWordCount example that ships with Spark show the following snippet: val updateFunc = (values: Seq[Int], state: Option[Int]) => { val currentCount = values.sum val previousCount = state.getOrElse(0) Some(currentCount + previousCount) } So if you have a state (K,V) the latest iteration will produce (K,V+V1) where the V1 is the update from the new batch...And I'm using + since the example shows simple addition/counting but your state could really be any operation (e.g.append or something). The assingment of previousCount shows how you retrieve or initialize the state for a key So I think what you seek is what happens "out of the box" (unless I'm misunderstanding the question) On Wed, Oct 1, 2014 at 4:13 AM, Chia-Chun Shih <chiachun.s...@gmail.com> wrote: > Hi, > > Are there any code examples demonstrating spark streaming applications > which depend on states? That is, last-run *updateStateByKey* results are > used as inputs. > > Thanks. > > > > > >