aggregate
Aggregates this PivotGroupBy using the provided statistics inside the AggregateDsl.
Returns a new DataFrame with the groupBy key columns and the pivot keys as top-level columns on top level, and the corresponding aggregated values in new nested columns.
AggregateDsl allows you to compute statistics on the columns within groups in PivotGroupBy and store the results as a new column using into. The given expression is applied to each group independently.
The resulting DataFrame has the same structure as the original PivotGroupBy; instead of the groups, there are new columns of aggregated values created with into.
You can use any of DataFrame Aggregation Statistics or any custom aggregation function.
Aggregated values can be either simple values, data rows or even data frames. Including them in the result using into will lead to creating a value column, a column group, or a frame column respectively in the resulting DataFrame while preserving the original structure at higher levels.
Check out for more information.PivotGroupBy Grammar
For more information: See pivot on the documentation website.
Example
df.pivot { city }.groupBy { name.firstName }.aggregate {
// Сount rows within each firstName" × "city" combination group and store the result
// into a new "total" column (a new sub-column under each pivot key column)
count() into "total"
// Compute the maximum in "age" column within each group
// and store it into a new "maxAge" column
// Defaults to -1 for empty groups.
max { age } default -1 into "maxAge"
}Return
A new DataFrame with the results of the aggregation applied to each group.
Parameters
The aggregation logic defined using AggregateDsl.