Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add summarize docs for "by" without an aggregate function #5216

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>] ...]
Comment on lines +8 to +12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After seeing the first iteration of this PR, @nwt correctly pointed out that the expanded/corrected original synopsis line was way too long and complex. His first thought on how to improve it was to break it out into more lines, so that's what I've done on this next iteration and indeed I'm liking it more. I like leading with the shorter one that represents a very common use, then builds up to the full/beastly one, so if a user is learning incrementally hopefully they'll get the idea.

```
### 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"}
```