Skip to content

feat(sid): keyed ExactAgg — MultipleSum / MultipleIncrease / MultipleMinMax - #210

Merged
zzylol merged 1 commit into
mainfrom
refactor/sid-keyed-exact-agg
May 14, 2026
Merged

zzylol merged 1 commit into
mainfrom
refactor/sid-keyed-exact-agg

Conversation

@zzylol

@zzylol zzylol commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the keyed-ExactAgg gap. Sum / Rate / Increase / Count{Exact} with non-empty by clauses now lower to multi-pop accumulator variants, and matching/capability satisfaction recognise the single-pop ⇆ multi-pop equivalence.

Three pieces

  1. BindExactAgg.apply: keyed input → ExactAgg(MultipleSum / MultipleIncrease); unkeyed unchanged.
  2. policy_capability: MultipleSum/Increase/MinMax now map to Capability::ExactAgg(<variant>) instead of None.
  3. Capability::is_satisfied_by: MultipleSum indexed satisfies Sum required (asymmetric; single-pop can't recover collapsed keys). The find_matching_policies group_by ⊆ policy.grouping_labels check handles the keys gate.

Test plan

  • 5 new BindExactAgg keyed tests + regression guard
  • 4 new find_matching_policies keyed tests
  • 3 existing tests updated
  • cargo check --workspace clean
  • cargo test --workspace --lib --bins green

🤖 Generated with Claude Code

…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>
@zzylol
zzylol merged commit 38ea431 into main May 14, 2026
@zzylol
zzylol deleted the refactor/sid-keyed-exact-agg branch July 17, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant