lazyUpdate
The lazyUpdate
method creates a new table containing a new, cached, formula column for each argument.
When using lazyUpdate
, cell values are stored in memory in a cache. Column formulas are computed on-demand and defer computation until it is required. Because it caches the results for the set of input values, the same input values will never be computed twice. Existing columns are referenced without additional memory allocation.
The syntax for the lazyUpdate
, updateView
, and update
methods is identical, as is the resulting table.
lazyUpdate
is recommended for small sets of unique input values. In this case, lazyUpdate
uses less memory than update
and requires less computation than updateView
. However, if there are many unique input values, update
will be more efficient because lazyUpdate
stores the formula inputs and result in a map, whereas update
stores the values more compactly in an array.
Syntax
table.lazyUpdate(columns...)
Parameters
Parameter | Type | Description |
---|---|---|
columns | String... | Formulas to compute columns in the new table; e.g., |
columns | Collection<? extends Selectable> | Formulas to compute columns in the new table; e.g., |
Returns
A new table that includes all the original columns from the source table and the newly defined columns.
Examples
In the following example, a new table is created, containing the square root of column C
. Because column C
only contains the values 2 and 5, sqrt(2)
is computed exactly one time, and sqrt(5)
is computed exactly one time. The values are cached for future use.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 2, 5, 5)
)
result = source.lazyUpdate("Y = sqrt(C)")
- source
- result