Skip to main content
Version: Java (Groovy)

Dial down 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 on the source table for data - must also 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.

snapshotWhen and snapshot

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

result = source.snapshotWhen(trigger)
result = source.snapshotWhen(trigger, features...)
result = source.snapshotWhen(trigger, features, stampColumns...)
result = source.snapshotWhen(trigger, options)
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 any columns of the same name, an error will occur. To avoid this, either rename conflicting columns, or omit duplicates in the trigger table via stamp columns.

The snapshot operation produces a static snapshot of a table at a specific point in time.

result = source.snapshot()

Sample at a regular interval

In this example, the source table updates every 0.5 seconds 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.

source = timeTable("PT00:00:00.5").update("X = new Random().nextInt(100)", "Y = sqrt(X)")

trigger = timeTable("PT00:00:05").renameColumns("TriggerTimestamp = Timestamp")

result = source.snapshotWhen(trigger)

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.

source = timeTable("PT00:00:01").updateView("X = 0.1 * i", "Y = Math.sin(X)")

// After some time
result = source.snapshot()