lazyUpdate method creates a new table containing a new, cached, formula column for each argument.
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.
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.
Formulas to compute columns in the new table; e.g.,
A new table that includes all the original columns from the source table and the newly defined columns.
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)")