In previous chapters, we took the data from the healthchecks topic, calculated the uptimes of the machines, and pushed this data into a topic called uptimes. Now, we are going to do this with KSQL.
At the time of writing, KSQL does not yet have a function to compare two dates, so we have the following two options:
- Code a user-defined function (UDF) for KSQL in Java
- Use the existing functions to make our calculation
As creating a new UDF is out of scope for now, let's go for the second option: use the existing functions to make our calculation.
The first step is to parse the startup time using the STRINGTOTIMESTAMP function, shown as follows (remember that we declared the date in string format, because KSQL doesn't yet have a DATE type):
ksql> SELECT event, factory, serialNumber, type, status, lastStartedAt, temperature, ipAddress, STRINGTOTIMESTAMP...