Skip to content

Commit

Permalink
Add summarize docs for "by" without an aggregate function (#5216)
Browse files Browse the repository at this point in the history
  • Loading branch information
philrz authored Aug 16, 2024
1 parent 97e0d9c commit 8e888f4
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions docs/language/operators/summarize.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
### Synopsis

```
[summarize] [<field>:=]<agg> [where <expr>][, [<field>:=]<agg> [where <expr>] ...] [by [<field>][:=<expr>] ...]
[summarize] [<field>:=]<agg>
[summarize] [<field>:=]<agg> [where <expr>][, [<field>:=]<agg> [where <expr>] ...]
[summarize] [<field>:=]<agg> [by [<field>][:=<expr>][, [<field>][:=<expr>]] ...]
[summarize] [<field>:=]<agg> [where <expr>][, [<field>:=]<agg> [where <expr>] ...] [by [<field>][:=<expr>][, [<field>][:=<expr>]] ...]
[summarize] by [<field>][:=<expr>][, [<field>][:=<expr>] ...]
```
### Description

The `summarize` operator consumes all of its input, applies an [aggregate function](../aggregates/README.md)
to each input value optionally organized with the group-by keys specified after
the `by` keyword, and at the end of input produces one or more aggregations
for each unique set of group-by key values.
In the first four forms, the `summarize` operator consumes all of its input,
applies an [aggregate function](../aggregates/README.md) to each input value
optionally filtered by a `where` clause and/or organized with the group-by
keys specified after the `by` keyword, and at the end of input produces one
or more aggregations for each unique set of group-by key values.

In the final form, `summarize` consumes all of its input, then outputs each
unique combination of values of the group-by keys specified after the `by`
keyword.

The `summarize` keyword is optional since it is an
[implied operator](../dataflow-model.md#implied-operators).
Expand Down Expand Up @@ -102,3 +111,14 @@ echo '{k:"foo",v:1}{k:"bar",v:2}{k:"foo",v:3}{k:"baz",v:4}' | zq -z 'set:=union(
{key:"baz",set:|[4]|}
{key:"foo",set:|[3]|}
```

Output just the unique key values:
```mdtest-command
echo '{k:"foo",v:1}{k:"bar",v:2}{k:"foo",v:3}{k:"baz",v:4}' | zq -z 'by k' - | sort
```
=>
```mdtest-output
{k:"bar"}
{k:"baz"}
{k:"foo"}
```

0 comments on commit 8e888f4

Please sign in to comment.