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

What is a sliding window?

A sliding window is also called a hopping window. Unlike tumbling windows, sliding windows can overlap each other.

A sliding window has two parameters: windowDuration and slideDuration. windowDuration specifies the window size. slideDuration specifies the step size of each slide.
  • If the value of slideDuration is less than that of windowDuration, the windows overlap, and each element is assigned to multiple windows.
  • If the value of slideDuration is equal to that of windowDuration , the windows are tumbling windows.

Syntax of a sliding window function

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)