Click to copy

• Reviewed for ksqlDB 0.29

How to Get Start and End Date of Window Interval in ksqlDB

You can use WINDOWSTART and WINDOWEND to get the starting and ending timestamps from each window interval.

The e xample below shows starting window times, but the same applies to ending times:

SELECT
  WINDOWSTART, -- BIGINT
  FROM_UNIXTIME(WINDOWSTART), -- TIMESTAMP
  subreddit,
  MAX(active_user_count) as max_activity
FROM REDDIT
WINDOW TUMBLING (SIZE 1 HOUR)
GROUP BY SUBREDDIT
EMIT CHANGES;

that returns :

+---------------+-------------------------+------------+--------------+
|WINDOWSTART    |WINDOWSTART_AS_TIMESTAMP |SUBREDDIT   |MAX_ACTIVITY  |
+---------------+-------------------------+------------+--------------+
|1608804000000  |2020-12-24T10:00:00.000  |science     |479           |
|1608804000000  |2020-12-24T10:00:00.000  |arts        |24            |
|1608804000000  |2020-12-24T10:00:00.000  |technology  |98            |
|1608804000000  |2020-12-24T10:00:00.000  |news        |86            |
Note that WINDOWSTART and WINDOWEND are of type BIGINT. You can use FROM_UNIXTIME() to have them converted to TIMESTAMP values.
Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like