Aggregations

The DataStream API supports various aggregations such as min, max, sum, and so on. These functions can be applied on KeyedDataStream to get rolling aggregations:

In Java:

keyedInputStream.sum(0)
keyedInputStream.sum("key")
keyedInputStream.min(0)
keyedInputStream.min("key")
keyedInputStream.max(0)
keyedInputStream.max("key")
keyedInputStream.minBy(0)
keyedInputStream.minBy("key")
keyedInputStream.maxBy(0)
keyedInputStream.maxBy("key")

In Scala:

keyedInputStream.sum(0)
keyedInputStream.sum("key")
keyedInputStream.min(0)
keyedInputStream.min("key")
keyedInputStream.max(0)
keyedInputStream.max("key")
keyedInputStream.minBy(0)
keyedInputStream.minBy("key")
keyedInputStream.maxBy(0)
keyedInputStream.maxBy("key")

The difference between max and maxBy is that max returns the maximum value in a stream, but maxBy returns a key that has a maximum value. The same applies to min and minBy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset