Skip to content

Commit b51daac

Browse files
committed
fix: Fixed spring-projectsGH-3509 Fixed the issue where FilterExpressionTextParser failed to parse Long type values.
Signed-off-by: Sun Yuhan <[email protected]>
1 parent 5cb5c90 commit b51daac

File tree

11 files changed

+1062
-993
lines changed

11 files changed

+1062
-993
lines changed

spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionTextParser.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
* }</pre>
9898
*
9999
* @author Christian Tzolov
100+
* @author Sun Yuhan
100101
*/
101102
public class FilterExpressionTextParser {
102103

@@ -266,6 +267,14 @@ public Filter.Operand visitNotExpression(NotExpressionContext ctx) {
266267
return new Filter.Expression(Filter.ExpressionType.NOT, this.visit(ctx.booleanExpression()), null);
267268
}
268269

270+
@Override
271+
public Filter.Operand visitLongConstant(FiltersParser.LongConstantContext ctx) {
272+
String text = ctx.getText();
273+
// Remove the trailing 'l' or 'L'
274+
long value = Long.parseLong(text.substring(0, text.length() - 1));
275+
return new Filter.Value(value);
276+
}
277+
269278
public Filter.Expression castToExpression(Filter.Operand expression) {
270279
if (expression instanceof Filter.Group group) {
271280
// Remove the top-level grouping.

spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/Filters.interp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
token literal names:
22
null
33
null
4+
null
45
'.'
56
','
67
'['
@@ -29,6 +30,7 @@ null
2930

3031
token symbolic names:
3132
null
33+
LONG_SUFFIX
3234
WHERE
3335
DOT
3436
COMMA
@@ -66,4 +68,4 @@ constant
6668

6769

6870
atn:
69-
[4, 1, 26, 89, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 34, 35, 3, 2, 1, 0, 35, 36, 5, 7, 0, 0, 36, 40, 1, 0, 0, 0, 37, 38, 5, 20, 0, 0, 38, 40, 3, 2, 1, 1, 39, 16, 1, 0, 0, 0, 39, 21, 1, 0, 0, 0, 39, 25, 1, 0, 0, 0, 39, 33, 1, 0, 0, 0, 39, 37, 1, 0, 0, 0, 40, 49, 1, 0, 0, 0, 41, 42, 10, 4, 0, 0, 42, 43, 5, 16, 0, 0, 43, 48, 3, 2, 1, 5, 44, 45, 10, 3, 0, 0, 45, 46, 5, 17, 0, 0, 46, 48, 3, 2, 1, 4, 47, 41, 1, 0, 0, 0, 47, 44, 1, 0, 0, 0, 48, 51, 1, 0, 0, 0, 49, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 3, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 52, 53, 5, 4, 0, 0, 53, 58, 3, 10, 5, 0, 54, 55, 5, 3, 0, 0, 55, 57, 3, 10, 5, 0, 56, 54, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 5, 5, 0, 0, 62, 5, 1, 0, 0, 0, 63, 64, 7, 0, 0, 0, 64, 7, 1, 0, 0, 0, 65, 66, 5, 25, 0, 0, 66, 67, 5, 2, 0, 0, 67, 71, 5, 25, 0, 0, 68, 71, 5, 25, 0, 0, 69, 71, 5, 22, 0, 0, 70, 65, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 69, 1, 0, 0, 0, 71, 9, 1, 0, 0, 0, 72, 74, 7, 1, 0, 0, 73, 72, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 87, 5, 23, 0, 0, 76, 78, 7, 1, 0, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 87, 5, 24, 0, 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0, 0, 10, 91, 1, 0, 0, 0, 12, 13, 5, 2, 0, 0, 13, 14, 3, 2, 1, 0, 14, 15, 5, 0, 0, 1, 15, 1, 1, 0, 0, 0, 16, 17, 6, 1, -1, 0, 17, 18, 3, 8, 4, 0, 18, 19, 3, 6, 3, 0, 19, 20, 3, 10, 5, 0, 20, 40, 1, 0, 0, 0, 21, 22, 3, 8, 4, 0, 22, 23, 5, 19, 0, 0, 23, 24, 3, 4, 2, 0, 24, 40, 1, 0, 0, 0, 25, 29, 3, 8, 4, 0, 26, 27, 5, 21, 0, 0, 27, 30, 5, 19, 0, 0, 28, 30, 5, 20, 0, 0, 29, 26, 1, 0, 0, 0, 29, 28, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 3, 4, 2, 0, 32, 40, 1, 0, 0, 0, 33, 34, 5, 7, 0, 0, 34, 35, 3, 2, 1, 0, 35, 36, 5, 8, 0, 0, 36, 40, 1, 0, 0, 0, 37, 38, 5, 21, 0, 0, 38, 40, 3, 2, 1, 1, 39, 16, 1, 0, 0, 0, 39, 21, 1, 0, 0, 0, 39, 25, 1, 0, 0, 0, 39, 33, 1, 0, 0, 0, 39, 37, 1, 0, 0, 0, 40, 49, 1, 0, 0, 0, 41, 42, 10, 4, 0, 0, 42, 43, 5, 17, 0, 0, 43, 48, 3, 2, 1, 5, 44, 45, 10, 3, 0, 0, 45, 46, 5, 18, 0, 0, 46, 48, 3, 2, 1, 4, 47, 41, 1, 0, 0, 0, 47, 44, 1, 0, 0, 0, 48, 51, 1, 0, 0, 0, 49, 47, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 3, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 52, 53, 5, 5, 0, 0, 53, 58, 3, 10, 5, 0, 54, 55, 5, 4, 0, 0, 55, 57, 3, 10, 5, 0, 56, 54, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 62, 5, 6, 0, 0, 62, 5, 1, 0, 0, 0, 63, 64, 7, 0, 0, 0, 64, 7, 1, 0, 0, 0, 65, 66, 5, 26, 0, 0, 66, 67, 5, 3, 0, 0, 67, 71, 5, 26, 0, 0, 68, 71, 5, 26, 0, 0, 69, 71, 5, 23, 0, 0, 70, 65, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 69, 1, 0, 0, 0, 71, 9, 1, 0, 0, 0, 72, 74, 7, 1, 0, 0, 73, 72, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 76, 5, 24, 0, 0, 76, 92, 5, 1, 0, 0, 77, 79, 7, 1, 0, 0, 78, 77, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 92, 5, 24, 0, 0, 81, 83, 7, 1, 0, 0, 82, 81, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 92, 5, 25, 0, 0, 85, 87, 5, 23, 0, 0, 86, 85, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 86, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 92, 1, 0, 0, 0, 90, 92, 5, 22, 0, 0, 91, 73, 1, 0, 0, 0, 91, 78, 1, 0, 0, 0, 91, 82, 1, 0, 0, 0, 91, 86, 1, 0, 0, 0, 91, 90, 1, 0, 0, 0, 92, 11, 1, 0, 0, 0, 11, 29, 39, 47, 49, 58, 70, 73, 78, 82, 88, 91]

spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/FiltersBaseListener.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,28 @@ public void enterIdentifier(FiltersParser.IdentifierContext ctx) {
276276
public void exitIdentifier(FiltersParser.IdentifierContext ctx) {
277277
}
278278

279+
/**
280+
* {@inheritDoc}
281+
*
282+
* <p>
283+
* The default implementation does nothing.
284+
* </p>
285+
*/
286+
@Override
287+
public void enterLongConstant(FiltersParser.LongConstantContext ctx) {
288+
}
289+
290+
/**
291+
* {@inheritDoc}
292+
*
293+
* <p>
294+
* The default implementation does nothing.
295+
* </p>
296+
*/
297+
@Override
298+
public void exitLongConstant(FiltersParser.LongConstantContext ctx) {
299+
}
300+
279301
/**
280302
* {@inheritDoc}
281303
*

spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/FiltersBaseVisitor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ public T visitIdentifier(FiltersParser.IdentifierContext ctx) {
178178
return visitChildren(ctx);
179179
}
180180

181+
/**
182+
* {@inheritDoc}
183+
*
184+
* <p>
185+
* The default implementation returns the result of calling {@link #visitChildren} on
186+
* {@code ctx}.
187+
* </p>
188+
*/
189+
@Override
190+
public T visitLongConstant(FiltersParser.LongConstantContext ctx) {
191+
return visitChildren(ctx);
192+
}
193+
181194
/**
182195
* {@inheritDoc}
183196
*

0 commit comments

Comments
 (0)