flatmap a stream of a collection to a stream of its elements

The name of the picture


flatmap a stream of a collection to a stream of its elements



I have a stream of a sequence of events and want to flatmap it to a stream of the events.



I have problems with the syntax of the flatMap function


val stream = DataStream[Seq[Event]]

stream.flatMap(???)



Any help would be appreciated





please provide more code
– Sukumaar
yesterday





stream.flatMap(identity)
– Dima
yesterday


stream.flatMap(identity)




1 Answer
1



I suggest you look at the examples that come with Flink, such as this wordcount application:


val counts: DataStream[(String, Int)] = text
// split up the lines in pairs (2-tuples) containing: (word,1)
.flatMap(_.toLowerCase.split("\W+"))
.filter(_.nonEmpty)
.map((_, 1))
// group by the tuple field "0" and sum up tuple field "1"
.keyBy(0)
.sum(1)



The documentation also has helpful code snippets in scala (and java).






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS