Data transformations transform the data stream from one form into another. The input could be one or more data streams and the output could also be zero, or one or more data streams. Now let's try to understand each transformation one by one.
This is one of the simplest transformations, where the input is one data stream and the output is also one data stream.
In Java:
inputStream.map(new MapFunction<Integer, Integer>() { @Override public Integer map(Integer value) throws Exception { return 5 * value; } });
In Scala:
inputStream.map { x => x * 5 }
FlatMap takes one record and outputs zero, one, or more than one record.
In Java:
inputStream.flatMap(new FlatMapFunction<String, String>() { @Override public void flatMap(String value, Collector<String> out) throws Exception { for(String word: value.split(" ")){ out.collect(word); } } });
In Scala:
inputStream.flatMap ...