ablative docs
↑↓ move↵ openesc close
Stack Notebook ablative.com.au

Finishing

Ordering, limiting and windowing a pipeline, and the stages that turn it into one answer.

Open .md

Order and bound

limit bound

Stop the upstream after at most n records or values at this point in the pipeline.

  • n a whole number from 1 to 4294967295
collection("patients") | sort(.admitted; desc) | limit(2)
sort order

Order the whole upstream by a field before the quoted jq stage.

  • field a top-level field with a leading dot
  • direction optional desc after a semicolon
collection("patients") | sort(.admitted; desc)
desc order

Order the sort field from greatest to least instead of ascending order.

window bound

Keep records by their revision append version, never by a time inside the record.

  • from an included unsigned version or quoted RFC 3339 instant
  • to an excluded bound of the same form, or $now
collection("patients") | window("1970-01-01T00:00:00Z"; $now)
collection("patients") | window(120; 240)

One answer

count count

Consume the whole upstream and answer its size as the last stage.

patients(ward: "4B") | count
group_by group

Drain records before jq into key, count and values groups in jq value order; missing fields group under null and no continuation is available.

  • field a top-level field with a leading dot
collection("patients") | group_by(.ward)
percentile aggregate

Drain records before jq into one nearest-rank JSON number; empty numeric input gives null, zero selects the minimum, non-numbers are counted as skipped, and no continuation is available.

  • field a top-level numeric field with a leading dot
  • percentile a number from 0 to 100 inclusive
collection("patients") | percentile(.admitted; 95)