Repository navigation
feat(ddsketch)!: buckets-only DDSketch under ASAPv1 kind 05 01; 05 00 decodes with scalars dropped - #109
Draft
zzylol wants to merge 2 commits into
Draft
feat(ddsketch)!: buckets-only DDSketch under ASAPv1 kind 05 01; 05 00 decodes with scalars dropped#109zzylol wants to merge 2 commits into
zzylol wants to merge 2 commits into
Conversation
… with scalars dropped asap_sketchlib drops sum / min / max from the DDSketch state: they are a separate exact aggregate, and a delta (bucket indices and counts) cannot rebuild them. Go follows. - MarshalASAPv1 writes kind 05 01, metadata_version 1 and alpha, payload [counts, offset, negative_counts, negative_offset, zero_count]. - UnmarshalASAPv1 accepts 05 01, and the retired 05 00 (eight fields, sum / min / max read and dropped). - DDSketch loses its sum / min / max fields, Min() and Max(), the scalar decode rules, and the representative cache that only fed the sum. - Quantile reads the nearest-rank bucket representative for every q, q = 0 and q = 1 included (within alpha of the extremes), with no clamp. - asapv1_golden points at 08440a1 (ddsketch_buckets_* fixtures). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…any sign If count ever exceeded the buckets, Quantile returned the last positive bucket, or 0 when the positive store was empty. It now returns the last occupied bucket walked (negative, zero or positive), as Rust's value_at_rank does. Co-Authored-By: Claude Opus 5.5 <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.
Part of ProjectASAP/asap_sketchlib#250. Stacked on the DDSketch ASAPv1 codec PR #90 (branch
asapv1-only/ddsketch); base this PR on that branch. Mirrors ProjectASAP/asap_sketchlib#252.Why
asap_sketchlibdropssum,minandmaxfrom the DDSketch state. A sum or an extreme is a separate exact aggregate, not a DDSketch readout, and a delta (bucket indices and counts) cannot rebuild them: a delta-fed receiver ended with different scalars than the producer. Per Q-VER the payload change takes a new kind id,05 01. The Go codec has to follow, or it would encode a kind Rust no longer writes and reject the kind Rust now writes.What
asapv1.KindDDSketchis05 01. The newasapv1.KindDDSketchWithScalarsis05 00(retired: decoded, never encoded). The registry grows from 37 to 38 ids.DDSketch.MarshalASAPv1writes05 01:metadata_version1 andalpha, payload[counts, offset, negative_counts, negative_offset, zero_count]. It no longer switches between metadata versions 1 and 2.DDSketch.UnmarshalASAPv1accepts05 01, and05 00with its eight-field payload. The three scalars are read as float64 and dropped without any check.DDSketchis buckets only.Quantile(q)reads the bucket representative of the nearest rankceil(q*n), clamped to1..n, for everyq. Ifcountever exceeded the buckets, it returns the last occupied bucket of any sign; before, it returned the last positive one, or0when the positive store was empty.q = 0andq = 1are within alpha of the true extremes, and nothing is clamped to[min, max].sum,minandmax;Min()andMax(), read only by tests;addToSumandresetScalarsIfEmpty;checkState;reps,repEntry,repCacheSize,cachedValue,fillValue), which existed only to feedsuminaddOneFast.asapv1_goldenmoves froma70fa1ato08440a1(ddsketch: fixtures for the buckets-only kinds 05 01 / 05 81 sketchlib-golden-bytes#4). That span is 19 golden commits and includes the delta, admission and seed-derivation fixtures.How
sketches/DDSketch/asapv1.go: one five-field encode. The decoder usesasapv1.Splitand checks the kind against both ids, so it can choose 5 or 8 fields.checkState(counts, offset, negCounts, negOffset, zeroCount)keeps the span, empty-at-offset-0 and total-overflow rules on both encode and decode.sketches/DDSketch/DDSketch.go:Update,UpdateGOS,Merge,AddToBucket,addOneFast,ResetBucket,DrainBuckets,Clear,Cloneand the constructors no longer touch the scalars.Quantilekeeps the negative, then zero, then positive walk.Key code interfaces added / modified
wire/asapv1/kind.gosketches/DDSketch/asapv1.go,sketches/DDSketch/DDSketch.goUsage
Before this PR
The Go DDSketch kept
sum/min/max, encoded them under05 00, and returned exact extremes atq = 0 / 1.After this PR
The Go DDSketch is buckets only and encodes
05 01, byte for byte as Rust does. Retired05 00bytes still decode, and re-encode as theirddsketch_buckets_*twins.Verification
2d75744(codec) and1d5ca3d(Quantilefallback).go test ./sketches/DDSketch/: 37 top-level tests pass. Failing first: before this change,TestASAPv1Goldenfailed on the05 01fixtures. New or rewritten tests:TestASAPv1Golden: byte-for-byte onddsketch_buckets_{empty,positive,signed}_a001.TestASAPv1RetiredFixturesDecodeToBucketTwins:ddsketch_*(05 00) decode and re-encode as theddsketch_buckets_*bytes.TestASAPv1RetiredScalarsAreDropped: NaN, out-of-order and empty-style scalars under05 00still decode.TestQuantileEndpointsAreWithinAlpha,TestBucketFedSketchMatchesTheProducer.TestQuantilePastTheBucketsReadsTheLastOccupiedBucket: the fallback.TestSignedFixtureQuantilesMatchRust: compared with the Rust values at q = 0, 0.05, 0.1, 0.4, 0.75, 0.9 and 1, fromget_value_at_quantileonddsketch_buckets_signed_a001.TestASAPv1RejectsCraftedBytes: 05 01 vs 05 00 field counts, metadata version 2 now rejected.go test ./wire/asapv1/ -run TestRegistry: passes (38 ids).go test ./sketch_framework/OctoSketch/ ./sketch_framework/ExponentialHistogram/: pass.go vet ./...: clean.wire/asapv1'sTestGoldenFixturesandTestEveryFixtureIsWellFormedfail at golden08440a1on HLL / Count-Min / Count Sketch bytes (theseed_derivationkey) and on delta kinds (01 81,02 80,05 80,05 81, ...). Neither is in this branch's registry, because feat(ddsketch)!: ASAPv1 codec with signed values; drop the protobuf, msgpack, delta and gob formats #90's base predates main's delta-kind registry. With the golden pointer at feat(ddsketch)!: ASAPv1 codec with signed values; drop the protobuf, msgpack, delta and gob formats #90'sa70fa1a, the same package passes.tests/cross_languageneedsXTEST_DIR.Merge order
mainregistry PR (branchddsketch/kind-0501).asapv1-only/ddsketch) rebased onto Gomain, takingmain'swire/asapv1/kind.go(theregistry/kindEntryshape). That brings in05 01/05 81/05 00/05 80and the delta kinds.ddsketch/buckets-0501) restacked on the rebased feat(ddsketch)!: ASAPv1 codec with signed values; drop the protobuf, msgpack, delta and gob formats #90, with itskind.go/kind_test.gohunks dropped.Limitations
05 81/05 80here: feat(ddsketch)!: ASAPv1 codec with signed values; drop the protobuf, msgpack, delta and gob formats #90's base has no delta kinds and no Go DDSketch delta codec. The Gomainregistry PR registers them (see Merge order).🤖 Generated with Claude Code