Complete the code to create a tumbling window of 5 minutes.
KStream<String, String> windowedStream = stream.groupByKey().windowedBy(TimeWindows.of(Duration.[1](5))).count();
The TimeWindows.of(Duration.minutes(5)) creates a tumbling window of 5 minutes.
Complete the code to create a hopping window with size 10 minutes and advance interval 5 minutes.
KStream<String, String> hoppingWindowedStream = stream.groupByKey().windowedBy(SlidingWindows.ofTimeDifferenceWithNoGrace(Duration.ofMinutes(10)).[1](Duration.ofMinutes(5))).count();
grace() instead of advanceBy() changes grace period, not advance interval.until() or suppress() are unrelated to window advance.The advanceBy() method sets the advance interval for hopping windows.
Fix the error in the code to set a session window with 15 minutes inactivity gap.
KStream<String, String> sessionWindowedStream = stream.groupByKey().windowedBy(SessionWindows.[1](Duration.ofMinutes(15))).count();
withGap() or withInactivityGap() causes errors.The correct method to set the inactivity gap for session windows is of().
Fill both blanks to create a tumbling window of 1 minute and set a grace period of 30 seconds.
KStream<String, String> windowedStream = stream.groupByKey().windowedBy(TimeWindows.of(Duration.[1](1)).[2](Duration.ofSeconds(30))).count();
advanceBy instead of grace for grace period.The of(Duration.minutes(1)) sets the window size to 1 minute, and grace(Duration.ofSeconds(30)) sets the grace period to 30 seconds.
Fill all three blanks to create a hopping window of 15 minutes size, 5 minutes advance, and set a grace period of 1 minute.
KStream<String, String> hoppingWindowedStream = stream.groupByKey().windowedBy(SlidingWindows.ofTimeDifferenceWithNoGrace(Duration.of[1](15)).[2](Duration.of[3](5))).grace(Duration.ofMinutes(1)).count();
Minutes instead of lowercase minutes causes errors.The window size and advance interval use Duration.ofMinutes(), and the advance interval is set by advanceBy(). The grace period is set separately.