kafka-streams-wordcount
kafka-streams-wordcount copied to clipboard
FlapMap error ?
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 ?
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.