Transform step: aggregate
Groups rows and computes aggregations, optionally with windows and managed state.
Used inside a transform's steps list as type: aggregate. See Transforms for the full model.
Group-and-aggregate. Expression grammar varies by execution mode: • Stateless batch and streaming windowed (state.window set): any Spark SQL aggregate expression (e.g. sum(price * qty), stddev(value), corr(a, b), collect_set(...)) - Catalyst plans them. • Managed batch state (state.enabled: true, batch mode) and streaming running totals (no state.window): only single-function primitives over one column - sum(col), avg(col), count(col), count(*), min(col), max(col). Compound expressions must be precomputed with a 'derive' step upstream. Managed batch state persists per-group partials so re-runs merge across input batches; avg(col) is stored as paired sum + count partials.
Fields
| Field | Type | Default | Notes |
|---|---|---|---|
name (required) | string | - | - |
type | aggregate | - | - |
group_by | array of string | - | - |
columns (required) | array of object | - | - |
columns[].name (required) | string | - | - |
columns[].expr (required) | string | - | - |
state | object | - | Managed cross-batch state for the aggregate step. Storage is configured at deployment time and is not exposed here. |
state.enabled | boolean | - | Defaults to true. Set false to opt out of managed state for this step. |
state.late_arrival | object | - | Out-of-order tolerance. Set when records may arrive after their event time. |
state.late_arrival.column (required) | string | - | Input column that carries the event time, e.g. 'ts'. |
state.late_arrival.max_latency (required) | string | - | Maximum delay after 'column' the engine will accept before treating a record as too late, e.g. '10 minutes', '1 hour', '1 day'. Used as the watermark grace in streaming. |
state.window | object | - | Optional event-time window for streaming aggregate. When set, the streaming-native aggregate runs as groupBy(window(event_time, ...), keys).agg(...). When omitted, streaming aggregate runs as a running-totals aggregate via flatMapGroupsWithState. Ignored for batch. |
state.window.type (required) | tumbling or session | - | - |
state.window.duration | string | - | Window length for tumbling windows, e.g. '5 minutes', '1 hour'. |
state.window.idle_timeout | string | - | Idle duration that closes a session window, e.g. '10 minutes'. The session ends when no event arrives for this long after the previous one. |
Required: name, columns.
Minimal example
A aggregate step inside a transform:
Code