[core] Fix BSI reader predicate pruning for Long.MIN_VALUE boundary#8150
Open
lxy-9602 wants to merge 2 commits into
Open
[core] Fix BSI reader predicate pruning for Long.MIN_VALUE boundary#8150lxy-9602 wants to merge 2 commits into
lxy-9602 wants to merge 2 commits into
Conversation
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.
Purpose
Fix incorrect predicate pruning in
BitSliceIndexBitmapFileIndex.Readerwhen the query literal isLong.MIN_VALUE.Problem
The BSI reader uses
Math.abs(value)to convert negative literals before querying the negative BSI. However,Math.abs(Long.MIN_VALUE)overflows and returnsLong.MIN_VALUEitself (still negative) due to Java's two-complement arithmetic. This causes incorrect results for all comparison predicates:x > Long.MIN_VALUEx >= Long.MIN_VALUEx < Long.MIN_VALUEx <= Long.MIN_VALUEx == Long.MIN_VALUEx != Long.MIN_VALUERoot Cause
Math.abs(Long.MIN_VALUE) == Long.MIN_VALUE— the onlylongvalue for whichMath.absoverflows.Fix
Add an early check for
value == Long.MIN_VALUEinvisitIn,visitNotIn,visitLessThan,visitLessOrEqual,visitGreaterThan, andvisitGreaterOrEqual. Since the BSI writer cannot storeLong.MIN_VALUE(theAppenderrejects negative min), the index can never contain this value. Therefore:GT/GTEwithLong.MIN_VALUE→ return all non-null rowsLT/LTEwithLong.MIN_VALUE→ return emptyEQ/INwithLong.MIN_VALUE→ return emptyNEQ/NOT INwithLong.MIN_VALUE→ return all non-null rowsNote: The writer-side issue (
Math.abs(Long.MIN_VALUE)inStatsCollectList.collect()andserializedBytes()) is a known limitation — the writer rejectsLong.MIN_VALUEwith anIllegalArgumentException. A separate writer test is added to document this behavior.Testing
testReaderPredicatePruningWithLongMinValue— verifies all 6 predicates (>,>=,<,<=,==,!=) withLong.MIN_VALUEas the query literal against data containing negative values.testWriterCannotHandleLongMinValue— documents that the writer throwsIllegalArgumentException("values should be non-negative")when attempting to writeLong.MIN_VALUE.