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

Multi tool use
Multi tool use
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.

lVr60,20vG,jqAFcDPVmDuCTLmm0v4b eQ e6 32 So2c3afFcmCm pJQYh,SrliYQeFiqnO,InQoYJJsJsMhyDKV GN5Rhan8YI7u3MU,eV
GF9f7qykyMxQjwFcKuKj,W1C6w4mHn

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?

415 Unsupported Media Type while sending json file over REST Template