Create a time table
This guide will show you how to create a time table. A time table is a ticking, in-memory table that adds new rows at a regular, user-defined interval. Its sole column is a timestamp column.
Time tables are often used as trigger tables, which, through the use of snapshotWhen
, can:
- reduce the update frequency of ticking tables.
- create the history of a table, sampled at a regular interval.
timeTable
The timeTable
method creates a table that ticks at the input period. The period can be passed in as nanoseconds:
oneMinute = 60_000_000_000
result = timeTable(oneMinute)
Or as a duration string:
result = timeTable("PT2S")
In this example, the startTime
argument was not provided, so the first row of the table will be approximately the current time. See this document for more details.
Duration strings are formatted as "PTnHnMnS"
, where:
PT
is the prefix to indicate a durationn
is a numberH
,M
, andS
are the units of time (hours, minutes, and seconds, respectively)
timeTable with a start time
You can also pass a startTime
to specify the timestamp of the first row in the time table:
oneHourEarlier = minus(now(), parseDuration("PT1H"))
result = timeTable(oneHourEarlier, "PT2S").reverse()
When this code is run, result
is initially populated with 1800 rows of data, one for every two seconds in the previous hour.
timeTable as a blink table
By default, the result of timeTable is append-only. You can create a blink table with the TimeTable.Builder
by calling the builder's blinkTable
method. The resulting table only retains rows from the most recent update cycle:
result = timeTableBuilder().period("PT2S").blinkTable(true).build()