fix(frequencies): write the full empty preamble long in serialize#143
Merged
Merged
Conversation
An empty FrequentItemsSketch serialized to 6 bytes: the preamble declares one 8-byte preamble long, but serialization stopped after the flags byte. Deserialization (in Rust as well as the Java and C++ readers) consumes the full 8-byte preamble, so a serialized empty sketch failed to deserialize with an insufficient-data error. Emptiness is reachable from non-trivial streams: a map saturated with count-1 items purges every counter, so pipelines that persist sketches can hit the failure on real data. Write the two unused padding bytes so the empty encoding is one full preamble long, matching the Java and C++ implementations. Co-Authored-By: Claude Fable 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.
What
FrequentItemsSketch::serializeemits only 6 bytes for an empty sketch: the preamble declares one 8-byte preamble long, but serialization stops after the flags byte.deserializeconsumes the full 8-byte preamble before checking the empty flag, so a serialized empty sketch always fails to deserialize withinsufficient data: <unused>. The truncated form also diverges from the Java and C++ implementations, which both write the full preamble long for empty sketches.Empty sketches are reachable from non-trivial streams: a map saturated with count-1 items (e.g. unique identifiers) purges every counter, leaving an empty sketch that then cannot be persisted and restored.
Changes
serialize_inner, making the empty encoding one full preamble long and byte-compatible with the Java/C++ readers.