Skip to content

feat(sketch_algebra): unify SketchKind onto asap_sketch::SummaryKind - #400

Merged
zzylol merged 1 commit into
mainfrom
feat/unify-sketch-kind-b-to-a
Jul 21, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/unify-sketch-kind-b-to-a

Conversation

@zzylol

@zzylol zzylol commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Step 3 of the sketch-identity unification (design doc, Steps 1–2: ASAPController#141/#142, PR #399). Replaces sketch_algebra::{SketchKind, SketchParams} (5 approximate-sketch-only variants, heap-bearing as a with_heap params flag) with asap_sketch::{SummaryKind, SummaryParams} (14 variants: exact accumulators + approximate sketches, heap-bearing promoted to kind identity) across all 24 real consumers, then deletes the now-empty sketch_params.rs entirely.

Upstream: bumped ASAPController's pin to 150ef7d (merge of PR #142, "derive PartialOrd/Ord for SummaryKind") — needed for BTreeSet<SummaryKind> in the 5-sketch routing-connector emit path's deterministic-order contract. No serde needed upstream — confirmed by audit that every real emit path builds JSON/YAML by hand, never via serde_json::to_value on a whole struct. The existing Serialize/Deserialize derives on PhysicalExpr/BackendAggregation/EdgeSketchProcessor/GatewayMergeProcessor only ever backed #[cfg(test)] round-trip tests, now deleted (3) or rewritten to check Debug-string substrings / clone-equality instead (2), preserving what they actually verified.

Behavior-preservation notes (not a pure mechanical rename)

  • Wire text is unchanged. build_backend_aggregation_json's JSON shape is byte-identical — sketch_kind_to_backend_type/sketch_params_to_json read the new shape but produce the same strings/fields, including the pre-existing quirk where Cms's JSON never carried a with_heap key (only CountSketch's did) and heap_size was never emitted on this wire path at all.
  • Heap-bearing dispatch. Every function that used to match a bare SketchKind (Cms/CountSketch) regardless of with_heap now matches Cms | CmsWithHeap / CountSketch | CountSketchWithHeap so topk-bound aggregations keep routing through the same processor names, merge processors, and warm-shape classification as before.
  • The 5-sketch routing-connector path (FAMILY_ORDER, needed_families, family_to_proc) is bare-5-family-keyed by design — added a base_family() normalizer so a committed heap-bearing kind still matches its bare FAMILY_ORDER entry instead of being silently dropped. This fixes a real latent bug: without normalization, a metric committed to a heap-bearing family would have silently vanished from this emit path.
  • bind_cms_topk.rs now threads the real requested top-k k into heap_size (previously unrepresentable). The backend wire path doesn't read this field either way, so this is strictly more correct in-memory data with no observable behavior change.
  • SketchType <-> SummaryKind conversions moved to types.rs, next to SketchType's own definition (orphan rule).
  • Test expectations updated (not regressions) — several tests asserted a bare CountSketch/Cms kind for a topk-bound aggregation; the underlying behavior (heap-bearing wire params) was already correct before this change, only the enum value identifying it changes.

Test plan

  • cargo build --workspace — clean
  • cargo test -p control_plane — 822 passed, 1 pre-existing unrelated failure (invalid_sketch_type_override_falls_back_to_default)
  • cargo test -p data_plane --lib — 881 passed, unaffected

🤖 Generated with Claude Code

Step 3 of the sketch-identity unification (see
scratchpad/artifacts/enum-unification-plan.md). Replaces
sketch_algebra::{SketchKind, SketchParams} (5 approximate-sketch-only
variants, heap-bearing as a with_heap params flag) with
asap_sketch::{SummaryKind, SummaryParams} (14 variants: exact
accumulators + approximate sketches, heap-bearing promoted to kind
identity) across all 24 real consumers, then deletes the now-empty
sketch_params.rs entirely.

Upstream: bumped ASAPController's pin to 150ef7d (merge of PR #142,
"derive PartialOrd/Ord for SummaryKind") -- needed for
BTreeSet<SummaryKind> in the 5-sketch routing-connector emit path's
deterministic-order contract. No serde needed upstream: confirmed by
audit that every real emit path builds JSON/YAML by hand
(build_backend_aggregation_json etc.), never via serde_json::to_value
on a whole struct -- the existing Serialize/Deserialize derives on
PhysicalExpr/BackendAggregation/EdgeSketchProcessor/GatewayMergeProcessor
only ever backed #[cfg(test)] round-trip tests, which are now deleted
(3) or rewritten to check Debug-string substrings / clone-equality
instead (2), preserving what they actually verified.

Behavior-preservation notes (not a pure mechanical rename):

- Wire text is unchanged. build_backend_aggregation_json's JSON shape
  (aggregationType/aggregationSubType/parameters) is byte-identical --
  sketch_kind_to_backend_type/sketch_params_to_json were rewritten to
  read the new shape but produce the same strings/fields, including
  the pre-existing quirk where Cms's JSON never carried a with_heap
  key (only CountSketch's did) and heap_size was never emitted on this
  wire path at all.
- Heap-bearing dispatch. Every function that used to match a bare
  SketchKind (Cms/CountSketch) regardless of with_heap now matches
  `Cms | CmsWithHeap` / `CountSketch | CountSketchWithHeap` so
  topk-bound aggregations keep routing through the same processor
  names, merge processors, and warm-shape classification as before.
- The 5-sketch routing-connector path (FAMILY_ORDER, needed_families,
  family_to_proc) is bare-5-family-keyed by design (matching the
  retired SketchKind's total lack of heap distinction) -- added a
  base_family() normalizer so a committed heap-bearing kind still
  matches its bare FAMILY_ORDER entry instead of being silently
  dropped.
- bind_cms_topk.rs now threads the real requested top-k `k` into
  SummaryParams::{Cms,CountSketch}WithHeap.heap_size (previously
  unrepresentable -- with_heap was a bool with no size field). The
  backend wire path doesn't read this field either way, so this is
  strictly more correct in-memory data with no observable behavior
  change.
- SketchType <-> SummaryKind conversions (previously
  sketch_params::{impl From<SketchKind> for SketchType, impl
  From<SketchType> for SketchKind}) moved to types.rs, next to
  SketchType's own definition (orphan rule -- the impl must live in a
  crate owning one of the two types).
- Test expectations updated (not regressions): several tests asserted
  a bare CountSketch/Cms kind for a topk-bound aggregation; the
  underlying behavior (heap-bearing wire params) was already correct
  before this change, only the enum value identifying it changes.

Also fixes a real bug in five_sketch routing (`needed_families`,
`family_to_proc`, `family_to_keep_processors`) that would have
silently dropped a committed heap-bearing family before base_family()
normalization was added.

- cargo build --workspace: clean
- cargo test -p control_plane: 822 passed, 1 pre-existing unrelated
  failure (invalid_sketch_type_override_falls_back_to_default)
- cargo test -p data_plane --lib: 881 passed, unaffected

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol merged commit 88150c7 into main Jul 21, 2026
@zzylol
zzylol deleted the feat/unify-sketch-kind-b-to-a branch July 21, 2026 13:40
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