Skip to content
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 Bug - Handle unsigned long in sorting order assertion of LongHashSet #17207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Shailesh-Kumar-Singh
Copy link
Contributor

Description

The assertion logic in LongHashSet.java assumes signed long values, which leads to incorrect validation when dealing with unsigned long values. The sorted order check fails because value >= previousValue does not correctly handle unsigned comparisons.
I have described the Bug in detail in the issue - #17206

FIX

  1. Added a new constructor parameter (isUnsignedLong) to LongHashSet to indicate whether the values are unsigned.
  2. Updated assertion logic:
    • Used Long.compareUnsigned(value, previousValue) >= 0 for unsigned long values.
    • Maintained value >= previousValue for signed values.
  3. Refactored assertion check into a new helper method: assertBasedOnDataType().
  4. Modified SortedUnsignedLongDocValuesSetQuery.java to pass true when initializing LongHashSet for unsigned values.

Related Issues

Resolves #17206

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

Copy link
Contributor

✅ Gradle check result for 5844005: SUCCESS

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 72.31%. Comparing base (2847695) to head (5844005).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
.../main/java/org/apache/lucene/util/LongHashSet.java 33.33% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #17207      +/-   ##
============================================
- Coverage     72.42%   72.31%   -0.11%     
+ Complexity    65775    65754      -21     
============================================
  Files          5318     5318              
  Lines        305739   305745       +6     
  Branches      44349    44351       +2     
============================================
- Hits         221421   221094     -327     
- Misses        66184    66546     +362     
+ Partials      18134    18105      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shailesh-Kumar-Singh Shailesh-Kumar-Singh force-pushed the handle-unsigned-long-SEARCH_INDEXING branch from 5844005 to c967d83 Compare February 5, 2025 05:54
@Shailesh-Kumar-Singh Shailesh-Kumar-Singh force-pushed the handle-unsigned-long-SEARCH_INDEXING branch from c967d83 to f5a6b7f Compare February 5, 2025 05:58
Copy link
Contributor

github-actions bot commented Feb 5, 2025

❌ Gradle check result for f5a6b7f: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

import java.util.stream.LongStream;

/** Set of unsigned-longs, optimized for docvalues usage */
public final class UnsignedLongHashSet implements Accountable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests similar to TestDocValuesLongHashSet in Lucene ?

@reta reta added the backport 2.x Backport to 2.x branch label Feb 5, 2025
@reta
Copy link
Collaborator

reta commented Feb 5, 2025

@Shailesh-Kumar-Singh thank you, please add CHANGELOG.md entry for this change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch bug Something isn't working Search Search query, autocomplete ...etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Sorted Order Assertion in LongHashSet.java is incorrect
4 participants