Skip to content

fix(ingest): envelope-aware decoders for KLL / HLL / DDSketch / CountSketch - #26

Merged
zzylol merged 1 commit into
mainfrom
fix/sketch-envelope-decoders
Apr 17, 2026
Merged

zzylol merged 1 commit into
mainfrom
fix/sketch-envelope-decoders

Conversation

@zzylol

@zzylol zzylol commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

PR #14 fixed CountMinSketchAccumulator::from_sketchlib_proto_bytes to decode the SketchEnvelope wrapper DataCollector's sketchlib-go processors emit, falling back to bare proto for direct-encoded tests. The same bug existed for the other four sketch types — wiring any of them in a real deployment would fail-silent with decode errors on every data point.

This PR applies the envelope-first-then-bare-fallback pattern verbatim to:

  • CountSketchAccumulator::from_sketchlib_proto_bytes
  • DatasketchesKLLAccumulator::from_sketchlib_proto_bytes
  • HllSketchAccumulator::from_sketchlib_proto_bytes
  • DDSketchAccumulator::from_sketchlib_proto_bytes

On envelope decode success, dispatch on the oneof variant; on non-matching variant return a clear SketchEnvelope contains non-<Name> sketch error; on decode failure / empty oneof, fall back to bare decode.

Test plan

  • 8 new unit tests — two per accumulator (envelope-wrapped happy path + wrong-sketch-type rejection).
  • All 10 envelope tests pass (8 new + 2 pre-existing CMS).
  • 578 lib tests pass (up from 570).
  • clippy + fmt clean.

Impact

Unblocks real-world deployments wiring any of KLL / HLL / DDSketch / CountSketch processors from DataCollector. CMS already worked post-PR #14; this closes the pattern across the remaining sketch types.

🤖 Generated with Claude Code

…Sketch

PR #14 fixed `CountMinSketchAccumulator::from_sketchlib_proto_bytes`
to try `SketchEnvelope::decode` first and fall back to bare
`CountMinState`. DataCollector's sketchlib-go processors wrap every
sketch state in a `SketchEnvelope` via `SerializePortableFO` +
`proto.Marshal`, so the bare-proto decoder was producing "invalid
wire type" errors and silently falling through to §5.2 for every
real-world sketch data point.

The same bug existed for the other four sketch accumulators. This
PR applies the envelope-first-then-bare-fallback pattern verbatim to:

  * `CountSketchAccumulator::from_sketchlib_proto_bytes`
  * `DatasketchesKLLAccumulator::from_sketchlib_proto_bytes`
  * `HllSketchAccumulator::from_sketchlib_proto_bytes`
  * `DDSketchAccumulator::from_sketchlib_proto_bytes`

On envelope decode success, dispatch on the oneof variant and
extract the expected state. On non-matching variant, return a clear
`SketchEnvelope contains non-<Name> sketch` error instead of
silently producing garbage. On envelope decode failure or empty
oneof, fall back to bare proto decode so unit tests (which encode
states directly without the envelope) keep working.

Tested end-to-end via 8 new unit tests: two per accumulator
(envelope-wrapped happy path + wrong-sketch-type rejection). All 10
envelope tests pass (8 new + 2 pre-existing CMS), 578 lib tests
total (up from 570); clippy + fmt clean.

Before the fix, wiring any of these four processors in a real
deployment would fail with a decode error on every data point. The
CMS fix shipped in PR #14; this PR completes the pattern across the
remaining sketch types.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 99796e6 into main Apr 17, 2026
@zzylol
zzylol deleted the fix/sketch-envelope-decoders branch April 17, 2026 21:43
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