Return a new DStream by passing each element of the source DStream through a function func.
val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)
flatMap(func)
Similar to map, but each input item can be mapped to 0 or more output items.
//split words from line separated by space, such as sentence
val lines = ssc.socketTextStream("localhost", 29999
, StorageLevel.MEMORY_AND_DISK_SER)
val words = lines.flatMap(_.split(" "))