Skip to main content
Version: Python

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 snapshot_when, can:

  • reduce the update frequency of ticking tables.
  • create the history of a table, sampled at a regular interval.

time_table

The time_table method creates a table that ticks at the input period. The period can be passed in as nanoseconds:

from deephaven import time_table

minute = 1_000_000_000 * 60
result = time_table(period=minute)

Or as a duration string:

from deephaven import time_table

result = time_table(period="PT2S")
tip

Duration strings are formatted as "PTnHnMnS", where:

  • PT is the prefix to indicate a duration
  • n is a number
  • H, M, and S are the units of time (hours, minutes, and seconds, respectively)

time_table with a start time

You can also pass a start_time to specify the timestamp of the first row in the time table:

from deephaven import time_table
import datetime

one_hour_earlier = datetime.datetime.now() - datetime.timedelta(hours=1)

result = time_table(period="PT2S", start_time=one_hour_earlier).reverse()

When this code is run, result is initially populated with 1800 rows of data, one for every two seconds in the previous hour.

img

By default, the result of time_table is append-only. You can set the blink_table parameter to True to create a blink table, which only retains rows from the most recent update cycle:

from deephaven import time_table

result = time_table("PT00:00:02", blink_table=True)