Class KeyedTranspose
The keyedTranspose operation takes a source table with a set of aggregations and produces a new table where
the columns specified in rowByColumns are the keys used for the aggregation, and the values for the columns
specified in columnByColumns are used for the column names. An optional set of initialGroups can be
provided to ensure that the output table contains the full set of aggregated columns, even if no data is present yet
in the source table.
For example, given the following source table...
Date| Level
----------+----------
2025-08-05|INFO
2025-08-05|INFO
2025-08-06|WARN
2025-08-07|ERROR
... and the usage ...
Table t = keyedTranspose(source, List.of(AggCount("Count")), new String[] {"Date"}, new String[] {"Level"});
The expected output for table "t" is ...
Date| INFO| WARN| ERROR
----------+--------------------+--------------------+--------------------
2025-08-05| 2|(null) |(null)
2025-08-06|(null) | 1|(null)
2025-08-07|(null) |(null) | 1
In the example, you can see that the column names (e.g. INFO, WARN, ERROR) are taken from the values occurring for
Level. But what if there are multiple aggregations or multiple columnByColumns specified? The
resulting column names may yield duplicates.
To avoid conflicts, the column naming works according to the following contract:
- If
aggregations= 1 andcolumnByColumns= 1: Column names are the value of thecolumnByColumnscolumn. (ex. INFO, WARN) - If
aggregations> 1: Column names are prefixed with the aggregation column name. (ex. Count_INFO, MySum_INFO) - If
columnByColumns> 1: Values for the original columns are separated by an underscore (ex. INFO_OTHER1, WARN_OTHER2) - If Illegal Characters: Purge characters that are invalid for Deephaven column names. (ex. "1-2.3/4" becomes "1234")
- If Starts with Number: Add the prefix "column_" to the column name. (ex. column_123)
- If Duplicate Column Name: Add a suffix to differentiate the columns. (ex. INFO, INFO2)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe behavior when a new column is detected. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TablekeyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns) Transpose the source table using the specified aggregations, row and column keys.static TablekeyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns, Table initialGroups) Transpose the source table using the specified aggregations, row and column keys, and an initial set of groups.static TablekeyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns, Table initialGroups, KeyedTranspose.NewColumnBehavior newColumnBehavior) Transpose the source table using the specified aggregations, row and column keys, and an initial set of groups.
-
Constructor Details
-
KeyedTranspose
public KeyedTranspose()
-
-
Method Details
-
keyedTranspose
public static Table keyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns) Transpose the source table using the specified aggregations, row and column keys.If a new column is detected, then the result table produces an error.
- Parameters:
source- The source table to transpose.aggregations- The aggregations to apply to the source table.rowByColumns- The columns to use as row keys in the transposed table.columnByColumns- The columns whose values become the new aggregated columns.- Returns:
- A new transposed table with the specified aggregations applied.
-
keyedTranspose
public static Table keyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns, Table initialGroups) Transpose the source table using the specified aggregations, row and column keys, and an initial set of groups.If a new column is detected, then the result table produces an error.
- Parameters:
source- The source table to transpose.aggregations- The aggregations to apply to the source table.rowByColumns- The columns to use as row keys in the transposed table.columnByColumns- The columns whose values become the new aggregated columns.initialGroups- An optional initial set of groups to ensure all columns are present in the output.
-
keyedTranspose
public static Table keyedTranspose(Table source, Collection<? extends Aggregation> aggregations, Collection<? extends ColumnName> rowByColumns, Collection<? extends ColumnName> columnByColumns, Table initialGroups, KeyedTranspose.NewColumnBehavior newColumnBehavior) Transpose the source table using the specified aggregations, row and column keys, and an initial set of groups.- Parameters:
source- The source table to transpose.aggregations- The aggregations to apply to the source table.rowByColumns- The columns to use as row keys in the transposed table.columnByColumns- The columns whose values become the new aggregated columns.initialGroups- An optional initial set of groups to ensure all columns are present in the output.newColumnBehavior- The behavior when a new column would be added
-