This topic describes how to use the sliding window function in Spark Streaming SQL.

What is a sliding window?

A sliding window is also called a hop window. Unlike tumbling windows, sliding windows can overlap each other. A sliding window has two parameters: windowDuration and slideDuration. The slideDuration parameter indicates the step size of each slide. The windowDuration parameter indicates the window size.
  • If the value of the slideDuration parameter is less than that of the windowDuration parameter, the windows overlap each other, and each element is assigned to multiple windows.
  • If the value of the slideDuration parameter equals that of the windowDuration parameter, the windows are tumbling windows.

Syntax

GROUP BY HOPPING (colName, windowDuration, slideDuration) 

Example

SELECT avg(inv_quantity_on_hand) qoh
FROM kafka_inventory
GROUP BY HOPPING (inv_data_time, interval 1 minute, interval 30 second)