FunctionGeneratedTableFactory

The FunctionGeneratedTableFactory's create method 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. The method creates a table by running the user-defined tableGenerator function. This function runs once when the table is created, and then again whenever any of the sourceTables ticks or refreshIntervalMs milliseconds elapse.

Note

The tableGenerator may access data in the sourceTables, but should not perform any further operations on them without careful handling. Since table operations may be memoized, a table operation may return a table created by a previous invocation of the same operation. Since that result will not have been included in the sourceTables, it is not automatically treated as a dependency for purposes of determining when it is safe to invoke tableGenerator. This allows race conditions to exist between accessing the operation result and that result's own update processing. It is best to include all dependencies directly in sourceTables or only compute on-demand inputs under a LivenessScope.

Every refresh in which the supplier produces a table replaces the result in full: the table update removes all previous rows and adds all newly generated rows, with no modified rows and no shifts, even when the generated data is unchanged. A FunctionGeneratedTableSpec with a retaining-last supplier may decline to produce a table on a refresh, in which case the previous result is retained with no update. By default, the generated data is copied into the result, which uses a flat, contiguous RowSet. The FunctionGeneratedTableSpec form can instead delegate to the generated table's ColumnSources and RowSet, or present the result as a blink table; see Control the result with FunctionGeneratedTableSpec.

When transforming a table, users should generally prefer to use regular table operations instead of this factory because they can perform some operations incrementally. However, create might require less development effort for small tables.

Syntax

Parameters

ParameterTypeDescription
tableGeneratorSupplier<Table>

A function that returns a table to copy into the output table.

refreshIntervalMsint

The interval (in milliseconds) at which the tableGenerator function is re-run.

sourceTablesTable...

If the tableGenerator function is dependent on one or more ticking tables, the tables must be specified here. This will cause the generated table to be recomputed on each tick. Every source table must be a refreshing table.

specFunctionGeneratedTableSpec

A specification describing how the table is generated and refreshed. It combines a table supplier, an optional refresh trigger (dependency tables or a refresh interval), and the copyData, blinkTable, and tableDefinition options. See the how-to guide for details.

Returns

A table generated by the tableGenerator function. The result ticks when the call supplies a refresh trigger: one or more sourceTables, a positive refreshIntervalMs, or a spec carrying dependencies or a refresh interval. Without a trigger, the tableGenerator runs once and the result is static.

Example

In the following example, we create an execution context and a tableGenerator function, which we then use to generate a table that re-runs the tableGenerator function every 2000ms.

If the tableGenerator function depends on one or more ticking tables, the tables must be specified. Adding timeTable1 as a sourceTables... parameter causes the generated table to be recomputed on each tick of the time table.