Skip to content

fix: req_sketch truncated k to 8 bits - #552

Merged
proost merged 2 commits into
apache:masterfrom
rustyconover:fix/req-k-8-bit-truncation
Oct 30, 2026
Merged

proost merged 2 commits into
apache:masterfrom
rustyconover:fix/req-k-8-bit-truncation

Conversation

@rustyconover

Copy link
Copy Markdown
Contributor

req_sketch's constructor computes k_ with std::max<uint8_t>, so any k of 256 or more wraps around:

req_sketch<float>(256).get_k();  // 4
req_sketch<float>(500).get_k();  // 244
req_sketch<float>(1024).get_k(); // 4

Everything else already treats k as 16 bits: the constructor parameter, the k_ member and the serialized format. The documented range (and the Java implementation's check) is [4, 1024]. This changes the one std::max<uint8_t> to std::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 with 4 == 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

Comment thread req/include/req_sketch_impl.hpp Resolved

@proost proost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i fixed failure of ci. Can you rebase?

Rusty Conover and others added 2 commits October 29, 2026 12:00
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>
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.
@rustyconover
rustyconover force-pushed the fix/req-k-8-bit-truncation branch from 1320b4a to cb7bb32 Compare October 29, 2026 16:05
@proost
proost merged commit 31e615c into apache:master Oct 30, 2026
21 checks passed
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.

2 participants