Create a ring table
This guide will show you how to create a ring table from a blink table or an append-only table.
Ring tables are much less memory-intensive than append-only tables. While append-only tables can grow infinitely in size, ring tables only hold on to as many rows as the user tells them to - once a row passes out of that range, it is eligible to be deleted from memory.
Ring tables are mostly used with blink tables, which do not retain their own data for more than an update cycle. For example, a blink table only stores rows from the current update cycle, but could be converted to a ring table that preserves the last 5000 rows instead.
Examples
In this example, we'll create a ring table with a 3-row capacity from a simple append-only time table.
import io.deephaven.engine.table.impl.sources.ring.RingTableTools
source = timeTable("PT00:00:01")
result = RingTableTools.of(source, 3)
A more common use case is to create a ring table from a blink table to preserve some data history. The following example creates a ring table from a blink time table. In source
, old data is removed from memory as soon as new data enters the table. In result
, 5 rows are kept, which preserves 4 more rows than source
.
import io.deephaven.engine.table.impl.sources.ring.RingTableTools
source = timeTable("PT00:00:01").update("X = i")
result = RingTableTools.of(source, 5)
The following example creates a ring table from a time table that starts with 5 rows. The initialize
argument is not set, and so is True
by default. This means the ring table initially starts with all 5 rows populated.
import io.deephaven.engine.table.impl.sources.ring.RingTableTools
staticSource = emptyTable(5).update("X = i")
dynamicSource = timeTable("PT00:00:01").update("X = i + 5").dropColumns("Timestamp")
source = merge(staticSource, dynamicSource)
result = RingTableTools.of(source, 5)
The following example is identical to the one above, except initialize
is set to False
. Thus, when the query is first run, result
is empty.
import io.deephaven.engine.table.impl.sources.ring.RingTableTools
staticSource = emptyTable(5).update("X = i")
dynamicSource = timeTable("PT00:00:01").update("X = i + 5").dropColumns("Timestamp")
source = merge(staticSource, dynamicSource)
result = RingTableTools.of(source, 5, false)