Skip to content

Frequent items: raise a threshold below the maximum error to it, as Java, Go and Rust do - #604

Draft
stojkomilos wants to merge 4 commits into
apache:masterfrom
stojkomilos:milosh-stojko/fi-threshold-at-least-max-error
Draft

stojkomilos wants to merge 4 commits into
apache:masterfrom
stojkomilos:milosh-stojko/fi-threshold-at-least-max-error

Conversation

@stojkomilos

@stojkomilos stojkomilos commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

NOT READY FOR REVIEW YET

Changes

get_frequent_items(err_type, threshold) now uses max(threshold, get_maximum_error()) as its threshold. Before, it used the threshold as passed. The one-argument overload already passed the maximum error, so it does not change.

Why: with NO_FALSE_POSITIVES, a listed item can have a lower bound at or below the maximum error. A dropped item has a true count of at most the maximum error, so the listed item may be no more frequent than a dropped item. With the threshold at the maximum error, every listed item is more frequent than every dropped item.

Java, Go and Rust already clamp the threshold this way:

This makes C++ match them on the clamp. Java clamps the threshold to the maximum error before it applies either error type, and this pull request does the same. Java has only integer weights, so the float rounding case, where NO_FALSE_NEGATIVES rows can change, is C++-only. The comparison still differs. The docs say > in all four libraries: Java at 028462110 lines 375 and 381, Go at 5aaf53b lines 273 and 277, and C++ and Rust. Java and Go code use >=, which this pull request does not change. This pull request keeps >. The doc comment of the two-argument overload says the clamp, as Java's Javadoc does, and that, for integer weights, it has no effect on NO_FALSE_NEGATIVES.

This is a behavior change for existing callers. It changes no signature and no serialized format. Callers with an explicit threshold below the maximum error can get fewer rows. This only affects NO_FALSE_POSITIVES: a threshold of maximum error minus 1 used to return items whose lower bound equals the maximum error, and it no longer does. With integer weights, NO_FALSE_NEGATIVES results do not change. The Python binding (datasketches-python) passes a nonzero threshold through, so it changes too. Its threshold 0 already means the maximum error.

Checks

  • New test frequent items: threshold below the maximum error is raised to it fails on master (NO_FALSE_POSITIVES with threshold 0 returns item 8) and passes with this change. It also checks that any threshold below the maximum error is raised, and that a threshold at or above it is used as given.
  • fi_test passes on Release: 30 test cases, 181 assertions.
  • fi_test passes under ASan and UBSan with no sanitizer reports (GCC 10.5).
  • No Java test on main passes a threshold below the maximum error.

This pull request and its description were written by Isaac.

stojkomilos and others added 4 commits December 1, 2026 11:22
get_frequent_items(err_type, threshold) now uses max(threshold, offset),
as datasketches-java, -go and -rust do. The one-argument overload already
passed the maximum error.

Co-authored-by: Isaac <no-reply@databricks.com>
… as given

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…TIVES claim

Co-authored-by: Isaac <no-reply@databricks.com>

This branch has not been deployed

No deployments
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.

1 participant