Extract table values
Deephaven tables have methods to extract values from tables into the native programming language. Generally, this isn't necessary for Deephaven queries but may be useful for debugging and logging purposes, and other specific use cases such as using listeners.
ColumnVectors (positional index access)
The recommended way to extract values from a table by positional index is using ColumnVectors. This provides random access to column data by row position.
import io.deephaven.engine.table.vectors.ColumnVectors
result = newTable(
intCol("Integers", 1, 2, 3, 4, 5)
)
// Get value at positional index 1 (second row)
value = ColumnVectors.ofInt(result, "Integers").get(1)
println "Value at index 1: ${value}"
For different data types, use the appropriate ColumnVectors method:
ColumnVectors.ofInt()forintcolumnsColumnVectors.ofLong()forlongcolumnsColumnVectors.ofDouble()fordoublecolumnsColumnVectors.ofFloat()forfloatcolumnsColumnVectors.ofObject()for object columns
Warning
Random access via ColumnVectors.get(position) is less efficient than bulk iteration. Use iteration when processing multiple values.
table.getColumnSource() (row key access)
The getColumnSource method returns a ColumnSource that provides access to column data by row key, not positional index.
result = newTable(
intCol("Integers", 1, 2, 3, 4, 5)
)
columnSource = result.getColumnSource("Integers")
println columnSource
[!IMPORTANT] >
ColumnSourcemethods likeget(rowKey)use row keys, not positional indices. Row keys are the internal identifiers for rows and may not match positional indices, especially in filtered or modified tables.
For primitive columns, use type-specific methods for better performance:
// Get value for row key 2 using type-specific method
value = columnSource.getInt(2)
println "Value for row key 2: ${value}"
Type-specific ColumnSource methods:
getInt(rowKey)forintcolumnsgetLong(rowKey)forlongcolumnsgetDouble(rowKey)fordoublecolumnsgetFloat(rowKey)forfloatcolumnsget(rowKey)for object columns
table.columnIterator()
To loop over all values in a column, use columnIterator. This is the most efficient way to process all values.
iterator = result.columnIterator("Integers")
while (iterator.hasNext()) {
println iterator.next()
}