snapshot
snapshot
produces an in-memory copy of a source table that refreshes 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.
Syntax
trigger.snapshot(source)
trigger.snapshot(source, doInitialSnapshot)
Parameters
Parameter | Type | Description |
---|---|---|
trigger | Table | The table that triggers the snapshot. |
source | Table | The source table to snapshot. |
doInitialSnapshot | boolean |
|
Returns
A snapshot of the source table that updates when the trigger table changes.
Examples
In the following example, the source
table updates every 0.5 seconds with new data. The trigger
table updates every five 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("00:00:00.5").update(formulas=["X = (int) random.randint(0, 100)", "Y = sqrt(X)"])
trigger = time_table("00:00:05").rename_columns(cols=["TriggerTimestamp = Timestamp"])
result = trigger.snapshot(source_table=source)
In the following example, a static snapshot of the source
table is created at the instant snapshot
is called.
First, create the dynamic source
table.
from deephaven import time_table
import random
source = time_table("00:00:01").update(formulas=["X = (int) random.randint(0, 100)", "Y = sqrt(X)"])
Then, when desired, take a snapshot to freeze the dynamic table as a static table. empty_table
creates a table that never changes. The doInitialSnapshot = True
argument causes snapshot
to create a snapshot without requiring the trigger table to first tick. The trigger table never changes so the snapshot will not change.
from deephaven import empty_table
result = empty_table(0).snapshot(source_table=source,do_init=True)