function_generated_table
The function_generated_table function is useful for creating tables that are dependent on one or more ticking tables, or for creating tables that need to be refreshed at a regular interval. Because the table_generator is arbitrary Python, it can bring data from outside Deephaven, such as files or websites, into a live table, or build the result with libraries such as pandas or NumPy.
The function creates a table by running the user-defined table_generator function. This function runs once when the table is created, and then again whenever one of the source_tables ticks or refresh_interval_ms milliseconds elapse. Specify at most one of source_tables and refresh_interval_ms. When neither is specified, nothing triggers a refresh: the table_generator runs exactly once, and the result is a static table.
Every refresh in which the table_generator produces a table replaces the result in full. The table update removes all previous rows and adds all newly generated rows. It has no modified rows and no shifts, even when the generated data is unchanged. If both the previous result and the new table are empty, no update is sent.
A refresh in which the table_generator returns None produces no update and keeps the previous result. If the result is a blink table, it is cleared instead. The copy_data parameter controls how the result stores each replacement, and blink_table makes the result keep only the current cycle's rows.
When the input is already a Deephaven table, regular table operations are generally preferable. Many of them update incrementally, while a function-generated table replaces its whole result on every refresh. A function-generated table may require less development effort for small tables.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| table_generator | Callable[..., Table | None] | The table generator function. This function must return a table or |
| source_tables optional | Table | Sequence[Table] | None | The source tables the This parameter and Note
The It is best to include all dependencies directly in |
| refresh_interval_ms optional | int | None | The interval (in milliseconds) at which the This parameter and |
| exec_ctx optional | ExecutionContext | None | A custom execution context in which to run the |
| args optional | tuple | A tuple of positional arguments to pass to |
| kwargs optional | dict | None | Dictionary of keyword arguments to pass to |
| copy_data optional | bool | When When Defaults to |
| blink_table optional | bool | When This parameter requires a refresh trigger: |
| table_definition optional | TableDefinitionLike | None | A table definition that sets the result's columns and their order. When it is provided, every table the |
Returns
A new function-generated table.
Examples
The following example defines a table_generator function and re-runs it about every 2000 ms.
If the table_generator function reads from one or more ticking tables, pass those tables as source_tables so that the table_generator re-runs when they tick. In the following example, make_table creates one row for each row of the time table tt, so the table_generator recomputes the result each time tt ticks and the result grows.
The args and kwargs parameters pass positional and keyword arguments to the table_generator function.
The following table_generator returns None while the time table tt has no rows. Because the first invocation may return None, the example supplies a table_definition. The result has a Count column even before the table_generator produces its first table.
With blink_table=True, the result holds only the rows generated in the current update cycle. With a 2000 ms refresh interval, the result is empty between refreshes.
With copy_data=False, the result reads the generated table's data without copying it. The table_generator here returns a new static table on each refresh, so it meets the immutability requirement described for copy_data.