Transformations

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.

Map

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

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 ...

Get Learning Apache Flink now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.