Replace hyperloglogplus with Apache DataSketches HLL (lg_k=11)#2837
Merged
Replace hyperloglogplus with Apache DataSketches HLL (lg_k=11)#2837
Conversation
Switch tantivy's cardinality aggregation from the hyperloglogplus crate (HyperLogLog++ with p=16) to the official Apache DataSketches HLL implementation (datasketches crate v0.2.0 with lg_k=11, Hll4). This enables returning raw HLL sketch bytes from pomsky to Datadog's event query, where they can be properly deserialized and merged using the same DataSketches library (Java). The previous implementation required pomsky to fabricate fake HLL sketches from scalar cardinality estimates, which produced incorrect results when merged. Changes: - Cargo.toml: hyperloglogplus 0.4.1 -> datasketches 0.2.0 - CardinalityCollector: HyperLogLogPlus<u64, BuildSaltedHasher> -> HllSketch - Custom Serde impl using HllSketch binary format (cross-shard compat) - New to_sketch_bytes() for external consumers (pomsky) - Salt preserved via (salt, value) tuple hashing for column type disambiguation - Removed BuildSaltedHasher struct - Added 4 new unit tests (serde roundtrip, merge, binary compat, salt)
Collaborator
|
Can you check the performance before and after?
|
Collaborator
Author
PSeitz
approved these changes
Feb 12, 2026
This is an open-source repo — replace references to Datadog's event query with generic cross-language compatibility descriptions.
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
Switch tantivy's cardinality aggregation from the
hyperloglogpluscrate (HyperLogLog++ with p=16) to the official Apache DataSketches HLL implementation (datasketchescrate v0.2.0, lg_k=11, Hll4).Why
Pomsky currently fabricates fake HLL sketches from scalar cardinality estimates (
generate_sketch(count)). When event query merges these across shards, the fake hashes collide — producing incorrect cardinality. For counts >256, it returns an empty HLL, losing data entirely.Why DataSketches over other options
Official crate (datasketches = 0.2.0, released 2026-01-14).
Binary-compatible with datasketches-java (cross-language tests in the crate).
Same hash function (MurmurHash3 x64-128, seed=9001).
Same lg_k=11 as Java Union(LOG2M=11).
Zero conversion needed — pomsky just forwards raw bytes.
Logs-backend already supports DataSketches HLL via the
hll_data_sketch_valueprotobuf field (field 10). No changes needed in logs-backend or cloudprem-bridge.Changes
Cargo.toml:hyperloglogplus 0.4.1→datasketches 0.2.0CardinalityCollector:HyperLogLogPlus<u64, BuildSaltedHasher>→HllSketch(lg_k=11, Hll4)HllSketchbinary serialization format (for cross-shard transfer)to_sketch_bytes()method for external consumers (pomsky will call this)(salt, value)tuple hashing for column type disambiguationBuildSaltedHasherstructTesting
All 169 aggregation tests pass, including 10 cardinality-specific tests (6 existing + 4 new).
Follow-up PRs
generate_sketchhack → callcardinality.to_sketch_bytes(), return ashll_data_sketch_valuegenerate_sketchfunction and its test