Typorithm · medium

aggregateWindow

flux-aggregateinfluxdbaggregateWindowdownsampleyield
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn aggregateWindow

0%

Flux

aggregateWindow groups rows into fixed time windows (every: 5m) and reduces each with an aggregate (fn: mean) — that is downsampling over time. yield names and emits the result.

Raw time-series data is dense; aggregateWindow downsamples it by grouping rows into fixed windows and collapsing each window to a single value.

every: 5m sets the window width and fn: mean is the reducer, so each 5-minute slice becomes its average; swap fn for sum, max, min, or count as needed.

yield(name: "mean") labels and emits the table as a named result; without a yield, the pipeline still implicitly outputs, but yield lets you name and emit multiple results.

01

aggregateWindow buckets rows by time and reduces each.

02

every sets the window; fn sets the aggregate.

03

yield names and emits the result.

from(bucket: "metrics")
  |> range(start: -1h)
  |> aggregateWindow(every: 5m, fn: mean)
  |> yield(name: "mean")

Read the implementation

Connect each part of the code to the concept before you type.

1. Windowed aggregate

aggregateWindow groups rows into fixed time buckets and reduces each with an aggregate function.

aggregateWindow(every: 5m, fn: mean)

2. Window size

every: 5m sets the window width, producing one output point per 5-minute interval — that is downsampling.

every: 5m

3. Aggregate fn

fn: mean reduces each window to its average; you could use sum, max, count, and so on.

fn: mean

4. Yield output

yield names and emits a result table so it appears in the query output.

yield(name: "mean")

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

aggregateWindow: Lesson & Practice · Typorithm | ApplyDjinn