Skip to main content
Version: Java (Groovy)


aggBy applies a list of aggregations to table data.


aggBy(aggregation, groupByColumns...)
aggBy(aggregations, preserveEmpty)
aggBy(aggregations, preserveEmpty, initialGroups, groupByColumns)



The aggregation to apply. The following aggregations are available:

aggregationsCollection<? extends Aggregation>

A list of aggregations to compute. The following aggregations are available:


The columns to group by.

groupByColumnsCollection<? extends ColumnName>

The columns to group by.


Whether to keep result rows for groups that are initially empty or become empty as a result of updates. Each aggregation operator defines its own value for empty groups.


A table whose distinct combinations of values for the groupByColumns should be used to create an initial set of aggregation groups. All other columns are ignored. This is useful in combination with preserveEmpty == true to ensure that particular groups appear in the result table, or with preserveEmpty == false to control the encounter order for a collection of groups and thus their relative order in the result. Changes to initialGroups are not expected or handled; if initialGroups is a refreshing table, only its contents at instantiation time will be used. If initialGroups == null, the result will be the same as if a table with no rows was supplied.


In Python queries, as_list is needed to convert the Python list of aggregations to a Java compatible list.


If an aggregation does not rename the resulting column, the aggregation column will appear in the output table, not the input column. If multiple aggregations on the same column do not rename the resulting columns, an error will result, because the aggregations are trying to create multiple columns with the same name. For example, in table.aggBy([agg.AggSum(“X”), agg.AggAvg(“X”)]), both the sum and the average aggregators produce column X, which results in an error.


Aggregated table data based on the aggregation types specified in the agg_list.


In this example, AggFirst returns the first Y value as grouped by X.

import static io.deephaven.api.agg.Aggregation.AggFirst

source = newTable(
stringCol("X", "A", "B", "A", "C", "B", "A", "B", "B", "C"),
stringCol("Y", "M", "N", "O", "N", "P", "M", "O", "P", "M"),
intCol("Number", 55, 76, 20, 130, 230, 50, 73, 137, 214),

result = source.aggBy([AggFirst("Y")], "X")

In this example, AggGroup returns an array of values from the Number column (Numbers), and AggMax returns the maximum value from the Number column (MaxNumber), as grouped by X.

import static io.deephaven.api.agg.Aggregation.AggGroup
import static io.deephaven.api.agg.Aggregation.AggMax

source = newTable(
stringCol("X", "A", "B", "A", "C", "B", "A", "B", "B", null),
stringCol("Y", "M", "N", null, "N", "P", "M", null, "P", "M"),
intCol("Number", 55, 76, 20, 130, 230, 50, 73, 137, 214),

result = source.aggBy([AggGroup("Numbers = Number"),AggMax("MaxNumber = Number")], "X")