Repository navigation
Tuple: support custom update seeds, and check seed hashes - #785
Merged
Merged
Conversation
Java tuple sketches always hashed with the default seed, wrote a fixed seed hash, and never checked the seed hash when reading an image or combining sketches. C++, Go and Rust support custom seeds and reject mismatches. All API changes are additive overloads: - UpdatableTupleSketchBuilder.setSeed(), and a seed constructor on UpdatableTupleSketch, DoubleTupleSketch, IntegerTupleSketch, ArrayOfStringsTupleSketch and FdtSketch. - Seed constructors on TupleUnion, TupleIntersection and TupleAnotB, and seed overloads of the static TupleAnotB.aNotB methods and of the tuple JaccardSimilarity methods. - TupleSketch.heapifySketch(seg, deserializer, seed) and TupleSketch.getSeedHash(). Behavior: - Compact images record the sketch's seed hash (zero when empty, as in theta). Default-seed images are byte-for-byte unchanged. - Reading a non-empty compact image checks its seed hash. - Set operations check the seed hash of non-empty tuple and theta inputs, and their results carry the operation's seed hash. - The deprecated updatable form has no seed hash, so it is read as the default seed, and serializing an updatable sketch with a custom seed throws; compact() it first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leerho
force-pushed
the
tuple-custom-seed
branch
from
October 30, 2026 17:47
212cc54 to
74ed06c
Compare
Member
Author
|
Merging #784 (tuple PreambleUtil) caused a conflict with this PR in |
proost
approved these changes
Oct 31, 2026
proost
left a comment
Member
There was a problem hiding this comment.
Overall looks good to me, leave nit review
…hash The updatable (QuickSelectSketch) serialized form has no seed hash field, so an updatable sketch created with a custom seed cannot be serialized in that form. The check was in QuickSelectSketch.toByteArray() and compared seed hashes, because QuickSelectSketch has only the seed hash. Move the check to UpdatableTupleSketch.toByteArray(), which has the user's seed, and compare it with DEFAULT_UPDATE_SEED. This also refuses a custom seed whose 16-bit seed hash happens to equal the default seed hash. QuickSelectSketch.toByteArray() no longer checks anything: the other QuickSelectSketch instances are heapified from the updatable form, which always uses the default seed, or are the internal sketch of TupleUnion, which is never serialized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sh() The update seed should not be visible outside of the sketch. Only its 16-bit seed hash, which ThetaSketch.getSeedHash() already returns, is meant to be public. - Deprecate UpdatableThetaSketch.getSeed(). It will be removed in a future release. - HeapUpdateSketch no longer calls getSeed(). It computes its seed hash once, at construction, as the direct sketch does. - SketchTest compares seed hashes instead of seeds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdatableThetaSketchBuilder.toString() and ThetaSetOperationBuilder.toString() printed the configured update seed. Builder output often ends up in logs, which can be readable by people who also handle the sketch images. Print the seed hash instead, in the same hex | decimal form as the sketches' toString(). A seed whose seed hash is zero, which the sketches reject, is reported as invalid instead of throwing from toString(). The builders' getSeed() methods are unchanged. 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.
Summary
Java tuple sketches always hashed with the default seed. They wrote a fixed seed hash and never checked the seed hash, either when reading an image or when combining sketches. As a result, Java accepted images created with any seed, and set operations could silently mix sketches built with different seeds. The C++, Go and Rust tuple sketches support custom seeds and reject mismatches. This PR brings Java in line with them, and with Java theta.
API: all changes are additive overloads
No existing signature changes. The new methods and constructors are:
UpdatableTupleSketchBuilder.setSeed(long), and a seed constructor onUpdatableTupleSketch.DoubleTupleSketch,IntegerTupleSketch,ArrayOfStringsTupleSketchandFdtSketch.TupleUnion(nomEntries, summarySetOps, seed),TupleIntersection(summarySetOps, seed)andTupleAnotB(seed).TupleAnotB.aNotBmethods and of the 8 tupleJaccardSimilaritymethods. The Jaccard overloads match what Align theta and tuple JaccardSimilarity; check theta seeds in tuple set operations #782 added for theta.TupleSketch.heapifySketch(seg, deserializer, seed)and a publicTupleSketch.getSeedHash(), as onThetaSketchsince Align theta and tuple JaccardSimilarity; check theta seeds in tuple set operations #782.Behavior
SketchesStateException. Callcompact()first.UpdatableTupleSketch.toByteArray()makes this check by comparing the user's seed with the default seed, so a custom seed whose 16-bit seed hash happens to equal the default seed hash is refused too. C++ doesn't serialize updatable tuple sketches at all.For default-seed users nothing changes. The only new exceptions are seed mismatches, which used to produce wrong results silently.
Seed handling cleanup in theta
The update seed should never be visible outside a sketch. Only its 16-bit seed hash is public. Two theta changes follow from that:
UpdatableThetaSketch.getSeed()is deprecated in favor ofgetSeedHash(), and will be removed in a future release. Internal code no longer calls it.UpdatableThetaSketchBuilder.toString()andThetaSetOperationBuilder.toString()print the seed hash instead of the seed. Builder output often ends up in logs.The builders'
getSeed()methods are unchanged.Verification
mvn verifypasses, including javadoc and style checks.check_java_files,check_cpp_filesandcheck_go_files) pass forTupleCrossLanguageTest. Java still reads the C++ and Gotuple_int_*images, now with their seed hash checked.TupleCustomSeedTest. It covers:copy(),compact()and serialization;Filter;FdtSketch.toString()prints the seed hash and never the seed.🤖 Generated with Claude Code