Repository navigation
fix: req_sketch truncated k to 8 bits - #552
Open
rustyconover wants to merge 2 commits into
Open
rustyconover wants to merge 2 commits into
rustyconover wants to merge 2 commits into
Conversation
The constructor computed k_ with std::max<uint8_t>, so any k of 256 or more wrapped around: req_sketch<float>(256).get_k() returned 4 and req_sketch<float>(500).get_k() returned 244. k is a uint16_t everywhere else (the parameter, the member and the serialized format), and the documented range is [4, 1024], so use std::max<uint16_t>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
proost
reviewed
Oct 27, 2026
Validate the original constructor argument before allocating compactors so k = 1025 cannot round down into the supported range. Preserve existing lower-bound clamping and odd-k rounding, and document the constructor behavior. Cover both accuracy modes, the upper boundary, values above the limit, and the maximum uint16_t value. Verified the new regression fails before the fix and all 17 CTest targets pass on the EC2 ARM64 host with GCC 14.2.1.
This branch has not been deployed
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.
req_sketch's constructor computesk_withstd::max<uint8_t>, so anykof 256 or more wraps around:Everything else already treats
kas 16 bits: the constructor parameter, thek_member and the serialized format. The documented range (and the Java implementation's check) is [4, 1024]. This changes the onestd::max<uint8_t>tostd::max<uint16_t>; odd values still round down.Added a test,
req sketch: k above 255. It checks k of 256, 500 and 1024, an odd k (1001 → 1000), and that k = 1024 survives serialization in estimation mode. Without the fix it fails with4 == 256. With it, all REQ tests pass.We found this through the DuckDB DataSketches extension, where users asking for K = 1024 were silently getting K = 4.
🤖 Generated with Claude Code