view
The view
method creates a new formula table that includes one column for each argument.
When using view
, the data being requested is not stored in memory. Rather, a formula is stored that is used to recalculate each cell every time it is accessed.
The syntax for the view
and select
methods is identical, as is the resulting table. view
is recommended when:
- the formula is fast to compute,
- only a small portion of the data is being accessed,
- cells are accessed very few times, or
- memory usage must be minimized.
When memory usage or computation needs to be reduced, consider using select
, updateView
, update
, or lazyUpdate
. These methods have different memory and computation expenses.
When using view
or updateView
, non-deterministic methods (e.g., random numbers, current time, or mutable structures) produce unstable results. Downstream operations on these results produce undefined behavior. Non-deterministic methods should use select
or update
instead.
Syntax
table.view(columns...)
Parameters
Parameter | Type | Description |
---|---|---|
columns | String... | Formulas to compute columns in the new table:
|
columns | Collection<? extends Selectable> | Formulas to compute columns in the new table:
|
Returns
A new formula table that includes one column for each argument.
Examples
The following example returns only the column B
.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.view("B")
- source
- result
In the following example, the new table contains source column A
(renamed as X
), and column B
.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.view("X = A", "B")
- source
- result
The following example creates a table containing column A
, column B
(renamed as X
), and the square root of column C
(renamed as Y
). While no memory is used to store column Y
, the square root function is evaluated every time a cell in column Y
is accessed.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.view("A", "X = B", "Y = sqrt(C)")
- source
- result