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

What is a tumbling window?

When tumbling windows are used, each element is assigned to a window with the specified size. Tumbling windows are a series of fixed-sized, non-overlapping, and contiguous time intervals. For example, if a 5-minute tumbling window is defined, elements are assigned to windows based on time periods: [0:00, 0:05), [0:05, 0:10), [0:10, 0:15), and so on.

Syntax of a tumbling window function

GROUP BY TUMBLING ( colName, windowDuration ) 

Example

SELECT avg(inv_quantity_on_hand) qoh
FROM kafka_inventory
GROUP BY TUMBLING (inv_data_time, interval 1 minute)