Skip to main content
Version: Python

snapshot_history

snapshot_history produces an in-memory history of a source table that adds a new snapshot when another table, the trigger table, changes.

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.

caution

Because snapshot_history stores a copy of the source table for every trigger event, large source tables or rapidly changing trigger tables can result in large memory usage.

Syntax

trigger.snapshotHistory(source)

Parameters

ParameterTypeDescription
triggerTable

The table that triggers the snapshot.

sourceTable

The source table to snapshot.

Returns

An in-memory history of a source table that adds a new snapshot when the trigger table changes.

Examples

In the following example, there are two input tables. The source table updates every 0.01 seconds with new data. The trigger table updates every second. A new snapshot of the source table is added to the result table when the trigger table changes. This design pattern is useful for examining the history of a table.

from deephaven import time_table
import random

source = time_table("00:00:00.01").update(formulas=["X = i%2 == 0 ? `A` : `B`", "Y = (int)random.randint(0, 100)", "Z = sqrt(Y)"]).last_by(by=["X"])

trigger = time_table("00:00:01").rename_columns(cols=["TriggerTimestamp = Timestamp"])

result = trigger.snapshot(source)