kafka-streams-wordcount icon indicating copy to clipboard operation
kafka-streams-wordcount copied to clipboard

FlapMap error ?

Open Maatary opened this issue 7 years ago • 1 comments

Hi,

I do not understand that line:

source.flatMapValues(value-> Arrays.asList(pattern.split(value.toLowerCase()))).map((key, value) -> new KeyValue<Object, Object>(value, value))

In fact, the map is confusing because it expect a pair. value-> Arrays.asList(pattern.split(value.toLowerCase()))). is supposed to return a list of word not list pair. Hence i do not understand the chaining here.

Please can you explain that ?

Maatary avatar Mar 06 '17 23:03 Maatary

pattern.split will return an array (http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#split(java.lang.CharSequence))

I'm converting it to a list. Flatmap takes the stream of lists (or any other iterable), flattens it into a stream of events and applies the mapping (turning each (key, value) into (value,value)).

Hope this helps.

gwenshap avatar Mar 11 '17 01:03 gwenshap