-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound #4270
Conversation
Signed-off-by: Daniel Widdis <[email protected]>
if (topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO) { | ||
assertEquals(numDocs, topDocs.totalHits.value); | ||
} else { | ||
assertTrue(numDocs >= topDocs.totalHits.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just have the below
assertTrue(numDocs >= topDocs.totalHits.value);
rather the whole condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the test, our total documents (numDocs
) is not always over 1000, and so it is more precise to test for equality in the 1/3 of cases where a more accurate result will apply.
OpenSearch/server/src/test/java/org/opensearch/index/fielddata/AbstractStringFieldDataTestCase.java
Line 261 in 05a5819
final int numDocs = scaledRandomIntBetween(10, 3072); |
This will protect against a bug where totalHits
is always some small constant like 1, which would pass the lower bound test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I might argue we could add another assertion that totalHits.value >= 1000
in this case, but that might be overkill.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it's overkill...
Pre-commit failing because of the usual Spotless
|
Signed-off-by: Daniel Widdis <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thx for adding this check @dbwiddis! I had completely forgot about this change.
Shouldn't we back port this PR to 2.x branch? |
I labeled it to backport, let's see. |
…wer bound (#4270) Fixes tests to account for TotalHits uncertainty as of Lucene 9. Signed-off-by: Daniel Widdis <[email protected]> (cherry picked from commit 4643620)
…or TotalHits lower bound (#4867) * Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound (#4270) Fixes tests to account for TotalHits uncertainty as of Lucene 9. Signed-off-by: Daniel Widdis <[email protected]> (cherry picked from commit 4643620) * Added CHANGELOG. Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]> Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]> Co-authored-by: Daniel Widdis <[email protected]> Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
@dbwiddis Looking at the implementation here: not in love with conditions in specs. When is it one or the other? |
@dblock answering nearly two years later, sorry. The initial PR comment javadoc explains the difference. Lucene can compute the hit count and if it's > 1000 it makes it an approximate bound, indicated by the enum used for the conditional. |
Signed-off-by: Daniel Widdis [email protected]
Description
From Lucene's
IndexSearcher
javaDoc:The
AbstractStringFieldDataTestCase
assumed thetotalHits
value was exact.This fixes the test to test for either exact accuracy or lower bound, as appropriate.
Issues Resolved
Fixes #4238
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.