April 2017
Intermediate to advanced
532 pages
12h 39m
English
As a final example, we will apply the concept of stateful streaming using the updateStateByKey function to compute a global state of revenue and number of purchases per user, which will be updated with new data from each 10-second batch. Our StreamingStateApp app is shown here:
object StreamingStateApp { import org.apache.spark.streaming.StreamingContext
We will first define an updateState function that will compute the new state from the running state value and the new data in the current batch. Our state, in this case, is a tuple of (number of products, revenue) pairs, which we will keep for each user. We will compute the new state given the set of (product, revenue) pairs for the current batch and the accumulated ...
Read now
Unlock full access