snapshot_when
The snapshot_when method produces an in-memory copy 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.
Caution
When snapshot_when stores table history, it stores a copy of the source table for every trigger event. This means large source tables or rapidly changing trigger tables can result in large memory usage.
Syntax
A PartitionedTableProxy has a snapshot_when method with the same parameters. It accepts a table or another proxy as the trigger table and returns a PartitionedTableProxy.
Parameters
| Parameter | Type | Description |
|---|---|---|
| trigger_table | Table | The table that triggers the snapshot. This should be a ticking table, as changes in this table trigger the snapshot. |
| stamp_cols optional | Optional[Union[str, Sequence[str]]] | One or more column names to act as stamp columns. Each stamp column will be included in the final result, and will contain the value of the stamp column from the trigger table at the time of the snapshot. If only one column, a string or list can be used. If more than one column, a list must be used. The default value is |
| initial optional | bool | Determines whether an initial snapshot is taken upon construction. The default value is |
| incremental optional | bool | Determines whether the resulting table should be incremental. The default value is |
| history optional | bool | Determines whether the resulting table should keep history. The default value is |
Caution
The stamp columns from the trigger table appear in the result table. If the source table has a column with the same name as a stamp column, a snapshot without history raises an error. With history=True, Deephaven does not reliably detect the conflict. The stamp column's values can be silently lost, or the snapshot can fail. To avoid the conflict, rename the stamp column in the trigger table using rename_columns.
Returns
A new table that captures a snapshot of the source table whenever the trigger table updates.
Examples
In the following example, the source table adds a row every second and the trigger table adds a row every five seconds. Thus, the result table updates each time trigger adds a row, about every five seconds. The Timestamp column in the trigger is renamed to avoid a name conflict error.

Notice three things:
stamp_colsis left blank, so every column fromtriggeris included inresult.incrementalisFalse, so the entireTriggerTimestampcolumn inresultis updated each time the trigger table updates and always contains the latest value from theTriggerTimestampcolumn intrigger.historyisFalse, soresultholds only the latest snapshot ofsource. Each snapshot replaces the previous one instead of being appended.
In the following example, the code is nearly identical to the one above it. However, in this case, the Y column is given as the stamp key. Thus, the Timestamp column in the trigger table is omitted from the result table, which avoids a name conflict error. This is an alternative to renaming the column in the trigger table.

In the following example, history is set to True. Therefore, every row in source gets snapshotted and appended to result each time trigger adds a row, regardless of whether source has changed or not.

In the following example, incremental is set to True. Thus, only the rows of source that were added or modified since the last snapshot get the latest Y value. Earlier rows keep the Y value from the snapshot that captured them. Contrast this with the first and second examples given above.
