gwenshap / kafka-streams-wordcount

Apache License 2.0
60 stars 46 forks source link

FlapMap error ? #1

Open Maatary opened 7 years ago

Maatary commented 7 years ago

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 ?

gwenshap commented 7 years ago

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.