Repository navigation
Frequencies: getFrequentItems uses > threshold, as documented and as in C++ - #821
Draft
stojkomilos wants to merge 2 commits into
Draft
stojkomilos wants to merge 2 commits into
stojkomilos wants to merge 2 commits into
Conversation
…in C++ sortItems kept an item whose bound equals the threshold (ub >= threshold, lb >= threshold). The Javadoc says > threshold, and datasketches-cpp and datasketches-rust use >. Change both comparisons in FrequentItemsSketch and FrequentLongsSketch, and add a test for a bound equal to the threshold. Co-authored-by: Isaac <no-reply@databricks.com>
Also say why threshold 2 returns only b in severalItems. Co-authored-by: Isaac <no-reply@databricks.com>
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.
NOT READY FOR REVIEW YET
getFrequentItemsreturns an item when its bound is greater than or equal to the threshold (ub >= thresholdandlb >= thresholdinsortItems). This PR changes both comparisons to>, inFrequentItemsSketchand inFrequentLongsSketch. The serialized format does not change.Main argument: we want to match datasketches-cpp and datasketches java. Datasketches c++ and datasketches rust use > instead of >= . Java and Go use >= (although Go may have blind copied it from Java). The question remains which of the 2 to use
Argument for using > instead of >=: Logically it makes more sense. This check is used when you have "no false positives" flag. A no false positive (if I understood correctly) is that any element that is returned from the final array, should truly be in the top
<array size used>(eg. if an element appears only once (it hasc=1) and triggers a purge, we don't want to return it).I claim this: "
>=can return items that are not in the top k, and it can return an item that ties with a dropped item, and > can not"This no false positives thing is achieved in the following way:
c, they are guaranteed to have appeared a number of times that is in this range:[c, c+offset](both ends of range included). However elements that are not in the final array at the time of the getter of final result call, they appeared a number of times in the range[0, offset](both ends included).The only way to guarantee these 2 are disjoint is that their ranges don't overlap. This obviously then requires
offset < c, in other words, c > offset. Proof completeAnother argument against >= and for
>:getFrequentItems- src/main/java/org/apache/datasketches/frequencies/FrequentItemsSketch.java:367. It saysgetLowerBound(item) > thresholdChanges
FrequentItemsSketch.sortItemsandFrequentLongsSketch.sortItems:ub > thresholdandlb > threshold.getMaximumError()),NO_FALSE_POSITIVESno longer returns an item whose lower bound equals the maximum error.NO_FALSE_NEGATIVESreturns the same items as before, because every active item has an upper bound above the maximum error.LongsSketchTestalready assertsgetUpperBound() > thresholdandgetLowerBound() > thresholdfor the default threshold.ItemsSketchTest.severalItemscalledgetFrequentItems(3, NO_FALSE_POSITIVES)and expected itemb, whose count is 3. It now passes threshold 2.checkThresholdIsExclusiveinItemsSketchTestandLongsSketchTest: an item whose bound equals the threshold is not returned, with the default threshold and with an explicit one. On main, the two new tests fail, and so doesseveralItems.Checks
mvn clean package javadoc:javadocwith JDK 25: all 2481 tests pass, and the Javadoc builds.ItemsSketchTest.checkThresholdIsExclusive(line 553),LongsSketchTest.checkThresholdIsExclusive(line 860), andItemsSketchTest.severalItems(line 103,expected [1] but found [2]). The other 70 pass.This pull request and its description were written by Isaac.