title: Flink Streaming - apply function in windows
body: <p>I am new to flink and streaming as well. I want to apply a certain function per partition to each window of the stream (event time is used). What I have done so far is this:</p>
  
  <pre><code>val env = StreamExecutionEnvironment.getExecutionEnvironment
  env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
  
  val inputStream = env.readTextFile("dataset.txt")
        .map(transformStream(_))
        .assignAscendingTimestamps(_.eventTime)
        .keyBy(_.id)
        .timeWindow(Time.seconds(windowSize),Time.seconds(slidingStep))
  
  def transformStream(input: String): EventStream = {...}
  
  case class EventStream(val eventTime: Long, val id: String, actualEvent: String)
  </code></pre>
  
  <p>What I want to do is to apply a general function to each partition per window batch, maybe apply a complex processing algorithm or something similar. I have seen the method apply in the DataStream API but I did not understand how it works. In Flink API it says it is used like that in Scala:</p>
  
  <pre><code>inputStream.apply { WindowFunction }
  </code></pre>
  
  <p>Can someone explain what the apply method does or how it is used? An example in Scala would be preferrable. Does the apply method do what I want?</p>