Typorithm · easy

from |> range |> filter

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

Step 1 of 8 · intro card

Learn from |> range |> filter

0%

Flux

A Flux query is a pipeline: from picks a bucket, |> pipes each result into the next function, range limits the time window, and filter keeps only matching rows.

Flux is functional and pipe-forward: every query starts at a source and flows through transformations connected by the |> operator.

from(bucket: "metrics") names the bucket to read; range(start: -1h) restricts the result to the last hour so you never scan the whole bucket.

filter(fn: (r) => ...) runs a predicate against each row r, keeping only rows where the expression is true — here, the cpu measurement on host a.

01

from selects the source bucket.

02

|> pipes output into the next function.

03

range bounds the time window; filter keeps matching rows.

from(bucket: "metrics")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "cpu" and r.host == "a")

Read the implementation

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

1. Source bucket

from picks the data source: a bucket is InfluxDB's named container of time-series data.

from(bucket: "metrics")

2. Pipe-forward

The |> operator sends the output of one function as the input of the next, building a left-to-right pipeline.

|> range(start: -1h)

3. Time range

range narrows the data to a time window; start: -1h means the last hour relative to now.

range(start: -1h)

4. Row filter

filter keeps only rows where the predicate fn returns true, testing each row r's columns.

filter(fn: (r) => r._measurement == "cpu" and r.host == "a")

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.

from |> range |> filter: Lesson & Practice · Typorithm | ApplyDjinn