Skip to main content
Version: Java (Groovy)

columnsToRows

The columnsToRows method is used to convert a table's columns into rows.

Syntax

columnsToRows(source, labelColumn, valueColumns, labels, transposeColumns)
columnsToRows(source, labelColumn, valueColumn, transposeColumns...)
columnsToRows(source, labelColumn, valueColumn, labels, transposeColumns)

Parameters

ParameterTypeDescription
sourceTable

The table with multiple value columns.

labelColumnString

The output column name for the label column.

valueColumnsString[]

The output column names for the value columns.

For each output value column, all of the constituent input columns columns must have the same type. If the types are different, then an IllegalArgumentException is thrown. All value columns must have the same number of source columns.

valueColumnString

The output column name for the value column.

For each output value column, all of the constituent input columns columns must have the same type. If the types are different, then an IllegalArgumentException is thrown. All value columns must have the same number of source columns.

labelsString[]

The labels for the transposed columns. Must be parallel to transposeColumns.

transposeColumnsString[][]

An array parallel to valueColumns; each element is in turn an array of input column names that are constituents for the output column. The input columns within each element must be the same type, and the cardinality much match labels.

transposeColumnsString[]

The input column names to transpose. Must be parallel to labels.

transposeColumnsString...

The names of the columns to transpose. The label value is the name of the column.

Returns

The transformed table.

Example

In this example, we start with a table that is very wide compared to how tall it is. The information in the table would be easier to read if we reorganize it, which we will do with the columnsToRows method.

import io.deephaven.engine.table.impl.util.ColumnsToRowsTransform

source = newTable(
stringCol("Sym", "AAPL", "SPY"),
intCol("Val1", 1, 2),
doubleCol("D1", 7.7, 8.8),
doubleCol("D2", 9.9, 10.1),
intCol("Val2", 3, 4),
intCol("Val3", 5, 6),
doubleCol("D3", 11.11, 12.12)
)

result = ColumnsToRowsTransform.columnsToRows(
source,
"Name",
new String[]{"IntVal", "DubVal"},
new String[]{"A", "B", "C"},
new String[][]{new String[]{"Val1", "Val2", "Val3"},
new String[]{"D1", "D2", "D3"}}
)