Repository navigation
Closed
Labels
category:enhancementNew feature or requeststatus:needs-triageAn issue that hasn't had any proper look
Milestone
Description
Related problem
Related:
- A more sql-like group-by #2607
- Deprecate
split-bycommand #14019 - add
agg-byas a command that helps aggregate data with sum, avg, and count #14316
Describe the solution you'd like
Similar to sort-by, group-by should support multiple grouper arguments, as the rest parameter.
group-by ...(grouper)Examples will be demonstrated on this sample data, taken from split-by's examples
let data = [
[name, lang, year];
[andres, rb, "2019"],
[jt, rs, "2019"],
[storm, rs, "2021"]
]Without --to-table, the output would be in the form of nested records, which would also make split-by obsolete.
Output of the split-by command, and the suggested group-by should be the same.
> $data | group-by year | split-by lang
> $data | group-by lang year
╭────┬─────────────────────────────────────────╮
│ │ ╭──────┬──────────────────────────────╮ │
│ rb │ │ │ ╭─#─┬──name──┬─lang─┬─year─╮ │ │
│ │ │ 2019 │ │ 0 │ andres │ rb │ 2019 │ │ │
│ │ │ │ ╰─#─┴──name──┴─lang─┴─year─╯ │ │
│ │ ╰──────┴──────────────────────────────╯ │
│ │ ╭──────┬─────────────────────────────╮ │
│ rs │ │ │ ╭─#─┬─name─┬─lang─┬─year─╮ │ │
│ │ │ 2019 │ │ 0 │ jt │ rs │ 2019 │ │ │
│ │ │ │ ╰─#─┴─name─┴─lang─┴─year─╯ │ │
│ │ │ │ ╭─#─┬─name──┬─lang─┬─year─╮ │ │
│ │ │ 2021 │ │ 0 │ storm │ rs │ 2021 │ │ │
│ │ │ │ ╰─#─┴─name──┴─lang─┴─year─╯ │ │
│ │ ╰──────┴─────────────────────────────╯ │
╰────┴─────────────────────────────────────────╯With --to-table, the output should be a flat table (excluding items column) regardless of how many grouper arguments are used.
> $data | group-by lang year --to-table
╭─#─┬─group_1─┬─group_2─┬────────────items─────────────╮
│ 0 │ rb │ 2019 │ ╭─#─┬──name──┬─lang─┬─year─╮ │
│ │ │ │ │ 0 │ andres │ rb │ 2019 │ │
│ │ │ │ ╰─#─┴──name──┴─lang─┴─year─╯ │
│ 1 │ rs │ 2019 │ ╭─#─┬─name─┬─lang─┬─year─╮ │
│ │ │ │ │ 0 │ jt │ rs │ 2019 │ │
│ │ │ │ ╰─#─┴─name─┴─lang─┴─year─╯ │
│ 2 │ rs │ 2021 │ ╭─#─┬─name──┬─lang─┬─year─╮ │
│ │ │ │ │ 0 │ storm │ rs │ 2021 │ │
│ │ │ │ ╰─#─┴─name──┴─lang─┴─year─╯ │
╰─#─┴──lang───┴──year───┴────────────items─────────────╯Note: The columns will be named after the groupers' string form, and group{i} will be used for groupers that can't be stringified (closures).
Describe alternatives you've considered
No response
Additional context and details
No response
Metadata
Metadata
Assignees
Labels
category:enhancementNew feature or requeststatus:needs-triageAn issue that hasn't had any proper look
Activity
add multiple grouper support to `group-by` (#14337)