Handle fractional numbers in Qdrant filter converter - #6981
Open
Lubaoshuai wants to merge 1 commit into
Open
Lubaoshuai wants to merge 1 commit into
Lubaoshuai wants to merge 1 commit into
Conversation
Eq/Ne/In/Nin filter expressions converted numeric values with
Long.parseLong(value.toString()), which threw NumberFormatException for
any fractional number (e.g. Eq("price", 10.5)) and mishandled whole
doubles such as 5.0. Exact matches on fractional numbers are now
expressed as an inclusive range condition, integral numbers are matched
as longs without a string round-trip, and booleans are matched as
booleans. In/Nin lists reject fractional members with a clear exception
instead of an unparseable-number failure.
Signed-off-by: Lubaoshuai <128781758+Lubaoshuai@users.noreply.github.com>
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.
QdrantFilterExpressionConverterconverted numeric filter values withLong.parseLong(value.toString()), so any fractional number crashed the whole search with aNumberFormatException:Whole doubles failed the same way (
Eq("rating", 5.0)→"5.0"is not parseable as a long), and large floats crashed via scientific notation (1.0E7).Changes
buildEqCondition/buildNeCondition: integral numbers (Integer,Long,Short,Byte) are matched as longs directly fromNumber.longValue()without the string round-trip; fractional numbers are expressed as an inclusive range condition (gte = lte), since the Qdrant client'sConditionFactoryonly offers exact-match conditions for strings, longs and booleans;Booleanvalues are now matched as booleans instead of being rejected.buildInCondition/buildNInCondition: list members are converted viaNumber.longValue(), and a fractional member is rejected with a clearIllegalStateException(Qdrant's values-match has no float variant) instead of the previousNumberFormatException.How tested
New
QdrantFilterExpressionConverterTests(8 cases, plain JUnit, no Testcontainers) asserting the generated gRPC condition: EQ/NE with fractional numbers produce an inclusiveRange(gte = lte), EQ with integral numbers/booleans produce the correspondingMatch, IN/NIN with integral lists produce integer matches, and a fractional IN member raises a clear error../mvnw -am -pl vector-stores/spring-ai-qdrant-store testpasses (module: 44 tests, 0 failures).