miller/pkg/transformers/utils
John Kerl f9afae491f
Add mlr rank verb (#2178)
* stats1: add rank accumulator (#383)

Adds `mlr stats1 -a rank` for standard competition ranking (1,2,2,4,...)
on pre-sorted data, most useful with -s for a rank on every record.

* stats1: make rank order-independent by default, add --rank-sorted opt-in fast path

The rank accumulator previously only compared each value to the immediately
preceding record, silently giving wrong ranks for non-adjacent duplicates
(e.g. unsorted input, or interleaved -g groups). Default to correctly
computing standard competition rank from all values seen so far
(order-independent, buffers values, same approach as percentile
accumulators). Add --rank-sorted for callers who can promise sorted input
and want the previous O(1)-space streaming behavior instead.

* Revert "stats1: make rank order-independent by default, add --rank-sorted opt-in fast path"

This reverts commit aa45a591fe.

* Revert "stats1: add rank accumulator (#383)"

This reverts commit 96deed048a.

* Add mlr rank verb (#383)

Reverts the earlier stats1 -a rank / --rank-sorted approach: stats1 is a
reduce verb (many records -> one summary record per group) and rank is a
per-record annotator, so it never fit cleanly there -- it needed stats1's
-s iterative-stats escape hatch just to be useful, plus a bolted-on
sorted/unsorted split.

mlr rank is a dedicated verb modeled on mlr fraction: -f fields to rank,
-g optional group-by, output field <f>_rank. By default it's a two-pass
algorithm (buffers input, like fraction does) giving standard competition
rank (1,2,2,4,...) that's correct regardless of input order. --sorted
opts into a single-pass, O(1)-space streaming alternative for callers who
can promise pre-sorted input (e.g. via 'mlr sort' first).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Regenerate docs/man pages after merging main (sparkline verb)

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-07 17:35:18 -04:00
..
doc.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
join_bucket.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
join_bucket_keeper.go join: exit nonzero when the left file cannot be read (#2169) (#2171) 2026-07-06 17:34:33 -04:00
percentile_keeper.go Add mlr rank verb (#2178) 2026-07-07 17:35:18 -04:00
README.md Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
stats1_accumulators.go Performance and style fixes (#1981) 2026-02-18 09:19:31 -05:00
stats2_accumulators.go Convert if/else-if chains to typed switch statements (staticcheck QF1003) (#2112) 2026-06-28 18:27:42 -04:00
top_keeper.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
window_keeper.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
window_keeper_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00

These are data structures used by various verbs including join,stats1, and `top.