aggBy
aggBy
applies a list of aggregations to table data.
Syntax
aggBy(aggregation)
aggBy(aggregation, groupByColumns...)
aggBy(aggregations)
aggBy(aggregations, preserveEmpty)
aggBy(aggregations, preserveEmpty, initialGroups, groupByColumns)
Parameters
Parameter | Type | Description |
---|---|---|
aggregation | Aggregation | The aggregation to apply. The following aggregations are available: |
aggregations | Collection<? extends Aggregation> | A list of aggregations to compute. The following aggregations are available: |
groupByColumns | String... | The columns to group by. |
groupByColumns | Collection<? extends ColumnName> | The columns to group by. |
preserveEmpty | boolean | 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. |
initialGroups | Table | A table whose distinct combinations of values for the |
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.
Returns
Aggregated table data based on the aggregation types specified in the agg_list
.
Examples
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")
- source
- result
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")
- source
- result