Skip to main content

//clika-runtime/io.clika.runtime/Table

Table

[common]
class Table

A columnar frame: an ordered set of named, typed columns sharing one row count. Build one with create and addColumn / addStringColumn or read a CSV; read a column back as a tensor or a cell by row and column; the verbs (select, head, sortBy, filter, groupBy, join, ...) each answer a new frame and leave the source unchanged; the in-place operations (applyScalar, applyColumn, assignColumn) change a column of this frame. AutoCloseable: close releases the frame.

Table.create().use { frame ->
frame.addColumn("score", Tensors.of(floatArrayOf(3f, 1f, 2f), longArrayOf(3)))
frame.addStringColumn("name", listOf("c", "a", "b"))
frame.sortBy("score").use { sorted -> sorted.getString(0, "name") } // "a"
}

Types​

NameSummary
Companion[common]
object Companion

Properties​

NameSummary
columnNames[common]
val columnNames: List<String>
The column names, in column order.
numColumns[common]
val numColumns: Long
The number of columns.
numRows[common]
val numRows: Long
The number of rows.

Functions​

NameSummary
addColumn[common]
fun addColumn(name: String, values: Tensor)
Append a numeric column from a 1-D CPU tensor (its data copied in); the first column fixes the row count.
addStringColumn[common]
fun addStringColumn(name: String, values: List<String>)
Append a string column, one value per row.
applyColumn[common]
fun applyColumn(name: String, op: ColumnOp, other: Tensor)
Apply op element-wise with another column (read with column) to column name, in place.
applyScalar[common]
fun applyScalar(name: String, op: ColumnOp, scalar: Double)
Apply op with scalar to every element of column name, in place.
assignColumn[common]
fun assignColumn(name: String, values: Tensor)
Create or replace column name from a 1-D tensor.
close[common]
open fun close()
column[common]
fun column(name: String): Tensor
A numeric column as a 1-D tensor you own (a copy); a missing or string column fails typed.
contains[common]
fun contains(name: String): Boolean
True when a column named name exists.
copy[common]
fun copy(): Table
An independent deep copy of this frame.
filter[common]
fun filter(mask: Tensor): Table
The rows where the boolean mask (one element per row) is true.
getDouble[common]
fun getDouble(row: Long, column: String): Double
A float column's cell at row, widened to a double; a missing column, a null cell or another type fails typed.
getLong[common]
fun getLong(row: Long, column: String): Long
An integer or boolean column's cell at row, widened to a long.
getString[common]
fun getString(row: Long, column: String): String
A string column's cell at row.
groupBy[common]
fun groupBy(keys: List<String>, aggs: List<AggSpec>): Table
Group by keys and apply aggs: one row per group, the key columns then one column per aggregation.
hasNulls[common]
fun hasNulls(name: String): Boolean
True when a column carries at least one null cell.
head[common]
fun head(n: Long = 5): Table
A new frame of the first n rows.
isNull[common]
fun isNull(row: Long, column: String): Boolean
True when the column is absent or the cell at row is null (never fails).
join[common]
fun join(other: Table, on: List<String>, kind: JoinKind = JoinKind.INNER): Table
An equi-join with other on the on columns, present in both with one type.
nullCount[common]
fun nullCount(name: String): Long
The number of null cells in a column.
select[common]
fun select(names: List<String>): Table
A new frame holding only names, in that order.
slice[common]
fun slice(offset: Long, count: Long): Table
A new frame of count rows from offset.
sortBy[common]
fun sortBy(keys: List<SortKey>): Table
A new frame stably sorted by several keys, most significant first.
[common]
fun sortBy(column: String, order: SortOrder = SortOrder.ASCENDING): Table
A new frame stably sorted by one column.
summary[common]
fun summary(): String
The frame rendered as text (a large frame shows its head and tail).
tail[common]
fun tail(n: Long = 5): Table
A new frame of the last n rows.
toCsvString[common]
fun toCsvString(): String
The frame as CSV text; readCsvString reads it back.
toString[common]
open override fun toString(): String
unique[common]
fun unique(column: String): Table
The distinct values of a column in first-seen order, as a one-column frame.
valueCounts[common]
fun valueCounts(column: String): Table
Each distinct non-null value's frequency, as a value and count frame sorted by count descending.
writeCsv[common]
fun writeCsv(path: String)
Write the frame as CSV to path.