Skip to main content
Version: Python

How to reduce the update frequency of ticking tables

This guide will show you how to reduce the update frequency of ticking tables.

When a table updates, all of the children of the table, which depend upon the table as a data source, must be updated. For fast-changing data, this can mean a lot of computing to keep child tables up to date. Table snapshots allow the update frequency of a table to be reduced, which results in fewer updates of child tables. This can be useful when processing fast-changing data on limited hardware.

Syntax

The snapshot_when operation produces an in-memory copy of a table (source), which refreshes every time another table (trigger) ticks.

result = source.snapshot_when(trigger)
result = source.snapshot_when(trigger_table=trigger, stamp_cols=stamp_keys)
result = source.snapshot_when(trigger_table=trigger, initial=True)
result = source.snapshot_when(trigger_table=trigger, incremental=True)
result = source.snapshot_when(trigger_table=trigger, history=True)
note

The trigger table is often a time table, a special type of table that adds new rows at a regular, user-defined interval. The sole column of a time table is Timestamp.

caution

Columns from the trigger table appear in the result table. If the trigger and source tables have columns with the same name, an error will be raised. To avoid this problem, rename conflicting columns.

Sample at a regular interval

In this example, the source table updates every second with new data. The trigger table updates every 5 seconds, triggering a new snapshot of the source table (result). This design pattern is useful for reducing the amount of data that must be processed.

from deephaven import time_table
import random

source = time_table("PT1S").update(formulas=["X = (int)random.randint(0, 100)", "Y = sqrt(X)"])

trigger = time_table("PT5S").rename_columns(cols=["TriggerTimestamp = Timestamp"])

result = source.snapshot_when(trigger_table=trigger)

img

Create a static snapshot

Creating a static snapshot of a ticking table is as easy as calling snapshot on the table.

This example creates a ticking table, and then after some time, calls snapshot to capture a moment in the table's history.

from deephaven import time_table

source = time_table("PT0.1S").update_view(["X = 0.1 * i", "Y = Math.sin(X)"])

# After some time
result = source.snapshot()

img