Commit 0def7fa
fix(lower): topk over a bare selector ranks its own samples, preserving by-labels (#30)
`topk(k, <bare instant selector>) by (labels)` — e.g.
`topk(3, http_requests_total) by (job)` ("top-3 series per job") — mislowered.
The non-heavy-hitter path in `build`'s `Outer::TopK` else-branch defaulted a
bare selector argument (`inner.func == None`) to an implicit cross-series
`AggFunc::Sum`. That reducing `Sum` collapsed every label (including the `by`
partition keys) into a single `sum` column, so `Sort.partition_by = [job]` no
longer resolved at L3 — a regression surfaced reviewing the Partition →
`Sort.partition_by` reframe (#12, PR #18). It was also semantically wrong:
PromQL `topk` ranks the raw instant-vector samples, it does not sum them.
A bare selector now ranks over the `filtered_source` directly (label-
preserving), so `Sort.partition_by` ranks within each group. A range-vector-
function argument (`topk(k, rate(m[5m]))`) still reduces per series first —
also label-preserving — so those paths are unchanged, as are the heavy-hitter
`count_over_time` and `bottomk` cases.
Expected: `topk(3, http_requests_total) by (job)`
→ `Limit{3} → Sort{value desc, partition_by:[job]} → Scan`.
Tests: bare-selector topk by-label (ranks per group, no implicit Sum) and
bare-selector topk without `by` (ranks raw samples).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent a54b45d commit 0def7fa
2 files changed
Lines changed: 70 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
422 | | - | |
423 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
424 | 435 | | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | 436 | | |
431 | 437 | | |
432 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
0 commit comments