select
The select
method creates a new in-memory table that includes one column for each argument. Any columns not specified in the arguments will not appear in the resulting table.
When using select
, the entire requested dataset is evaluated and stored in memory.
The syntax for the select
and view
methods is identical, as is the resulting table. select
is recommended when:
- not all the source columns are desired in the result,
- the formula is expensive to evaluate,
- cells are accessed many times, and/or
- a large amount of memory is available.
When memory usage or computation needs to be reduced, consider using view
, updateView
, update
, or lazyUpdate
. These methods have different memory and computation expenses.
Syntax
table.select()
table.select(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 in-memory table that includes one column for each argument. If no arguments are provided, there will be one column for each column of the source table.
Examples
In the following example, select
has zero arguments. All columns are selected. While this selection appears to do nothing, it is creating a compact, in-memory representation of the input table, with all formulas evaluated.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.select()
- source
- result
In the following example, column B
is selected for the new table.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.select("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.select("X = A", "B")
- source
- result
In the following example, mathematical operations are evaluated and stored in memory for the new table.
source = newTable(
stringCol("A", "The", "At", "Is", "On"),
intCol("B", 1, 2, 3, 4),
intCol("C", 5, 6, 7, 8)
)
result = source.select("A", "X = B", "Y = sqrt(C)")
- source
- result