DynamicTableWriter
DynamicTableWriter creates a TableWriter for writing data to a real-time, in-memory table.
Syntax
DynamicTableWriter(header, constantValues)
DynamicTableWriter(header)
DynamicTableWriter(columnNames, columnTypes, constantValues)
DynamicTableWriter(columnNames, columnTypes)
DynamicTableWriter(definition)
DynamicTableWriter(definition, constantValues)
Parameters
| Parameter | Type | Description |
|---|---|---|
| columnNames | String[] | Column names. |
| columnTypes | Class[] | Column data types. |
| header | TableHeader | The names and types of the columns in the output table (and our input). |
| constantValues | Map<String, Object> | A Map of columns with constant values. |
| definition | TableDefinition | The table definition to create the Dynamic Table Writer for. |
Returns
A TableWriter.
Methods
DynamicTableWriter supports the following methods:
close()- Closes theTableWriter.flush()- Flushes theTableWriter.getColumnNames()- Returns a list of column names.getColumnTypes()- Returns a list of column types.getTable()- Returns a real-time, in-memory table.logRow(values...)- Writes a row of values to the table.size()- Returns the number of rows in the table.
Examples
In this example, DynamicTableWriter is used to create a table with two columns:
- The first contains the row number.
- The second contains a string.
import io.deephaven.engine.table.impl.util.DynamicTableWriter
columnNames = ["Numbers", "Words"] as String[]
columnTypes = [int.class, String.class] as Class[]
tableWriter = new DynamicTableWriter(columnNames, columnTypes)
result = tableWriter.getTable()
// The logRow method adds a row to the table
tableWriter.logRow(1, "Testing")
sleep(3000)
tableWriter.logRow(2, "Dynamic")
sleep(3000)
tableWriter.logRow(3, "Table")
sleep(3000)
tableWriter.logRow(4, "Writer")

The example above writes data to result from the main thread. As a result, the Deephaven web interface will not display the result table until the script finishes execution.
The example below uses a dedicated thread to write data to the table. The Deephaven web interface immediately updates to display all result table changes.
import io.deephaven.engine.table.impl.util.DynamicTableWriter
columnNames = ["Numbers", "Words"] as String[]
columnTypes = [int.class, String.class] as Class[]
tableWriter = new DynamicTableWriter(columnNames, columnTypes)
result = tableWriter.getTable()
// Thread to log data to the dynamic table
def thread = Thread.start {
def strings = ["Testing", "Dynamic", "Table", "Writer"]
for(int i = 0; i < 4; i++) {
// The logRow method adds a row to the table
tableWriter.logRow(i + 1, strings[i])
sleep(3000)
}
return
}