Click to copy
Working With Dates • 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 thatWINDOWSTART
andWINDOWEND
are of typeBIGINT
. You can useFROM_UNIXTIME()
to have them converted toTIMESTAMP
values.
Was this article helpful?