feat(sid): keyed ExactAgg — MultipleSum / MultipleIncrease / MultipleMinMax - #210
Merged
Merged
Conversation
…MinMax
Closes the last gap in the warm-tier ExactAgg routing. `Sum`,
`Rate`, `Increase`, `Count{Exact}` with non-empty `by` clauses now
lower to the multi-pop accumulator variants instead of being
rejected by `BindExactAgg`; `policy_capability` recognises multi-pop
policies; `is_satisfied_by` accepts multi-pop indexed capabilities
against single-pop required capabilities (asymmetric — single-pop
can't recover collapsed keys).
## Three pieces
1. **`BindExactAgg.apply`** no longer rejects `by != []`. Keyed
inputs lower to the `Multiple*` variant of the same accumulator
family:
- `Aggregate{Sum, by=[…]}` → `ExactAgg(MultipleSum)`
- `Aggregate{Rate{w}, by=[…]}` / `Increase{w}` → `ExactAgg(MultipleIncrease)`
- `Aggregate{Count{Exact}, by=[…]}` → `ExactAgg(MultipleSum)` (count = sum-of-1s)
2. **`policy_capability`** maps multi-pop AggregationType variants:
- `MultipleSum` → `Some(Capability::ExactAgg(MultipleSum))`
- `MultipleIncrease` → `Some(Capability::ExactAgg(MultipleIncrease))`
- `MultipleMinMax` → `Some(Capability::ExactAgg(MultipleMinMax))`
3. **`Capability::is_satisfied_by`** for `ExactAgg(req)` vs
`ExactAgg(have)`:
- Exact-match still satisfies (unchanged).
- `MultipleSum` indexed satisfies `Sum` required, and similarly
for Increase / MinMax. New helper `multi_pop_satisfies_single`.
- Cross-family combos (Sum vs MinMax etc.) remain non-satisfiable.
- One-way: a single-pop policy does NOT satisfy a multi-pop
required capability (keys are gone; can't recover).
The `find_matching_policies` `candidate.group_by_keys ⊆
policy.grouping_labels.labels` check is what ultimately gates
the keys dimension. Capability satisfaction tells you whether the
accumulator family is right; group_by tells you whether the
stored keys cover the query's projection.
## How keyed queries resolve end-to-end
```
PromQL `sum by (zone) (http_lat{zone=us-east})`
└─ analyzer → ASAPTierCandidate {
metric=http_lat, group_by={zone}, capability=ExactAgg(Sum),
spatial_filter_canonical=`{zone="us-east"}`, range=0 }
└─ find_matching_policies → searches registry for policies where:
metric=http_lat
group_by_keys ⊆ policy.grouping_labels.labels
ExactAgg(Sum).is_satisfied_by(policy_capability(cfg))
↑ matches MultipleSum via multi_pop_satisfies_single
spatial_filter equal
→ returns [policy_fp]
└─ SketchStore::sids_for_policy(policy_fp) → [sids]
└─ reducer per-key evaluation
```
## Test plan
- [x] 5 new `BindExactAgg` keyed tests + regression guard for unkeyed.
- [x] 4 new `find_matching_policies` keyed tests covering the
multi-pop-satisfies-single and key-coverage paths.
- [x] Updated 3 existing tests that locked in the rejected-keyed
behavior.
- [x] `cargo check --workspace` clean.
- [x] `cargo test --workspace --lib --bins` green.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the keyed-ExactAgg gap.
Sum/Rate/Increase/Count{Exact}with non-emptybyclauses now lower to multi-pop accumulator variants, and matching/capability satisfaction recognise the single-pop ⇆ multi-pop equivalence.Three pieces
BindExactAgg.apply: keyed input →ExactAgg(MultipleSum / MultipleIncrease); unkeyed unchanged.policy_capability:MultipleSum/Increase/MinMaxnow map toCapability::ExactAgg(<variant>)instead ofNone.Capability::is_satisfied_by:MultipleSumindexed satisfiesSumrequired (asymmetric; single-pop can't recover collapsed keys). Thefind_matching_policiesgroup_by ⊆ policy.grouping_labelscheck handles the keys gate.Test plan
BindExactAggkeyed tests + regression guardfind_matching_policieskeyed testscargo check --workspacecleancargo test --workspace --lib --binsgreen🤖 Generated with Claude Code