Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ private String unescapeStringValue(String in) {

@Override
public Filter.Operand visitIntegerConstant(FiltersParser.IntegerConstantContext ctx) {
return new Filter.Value(Integer.valueOf(ctx.getText()));
String text = ctx.getText();
try {
return new Filter.Value(Integer.valueOf(text));
}
catch (NumberFormatException ex) {
// Fall back to Long for literals that exceed the int range (gh-4705).
return new Filter.Value(Long.valueOf(text));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ public void testEQ() {
assertThat(this.parser.getCache().get("WHERE " + "country == 'BG'")).isEqualTo(exp);
}

@Test
public void testLongValueLiteral() {
// id == 9223372036854775807 (Long.MAX_VALUE, exceeds the int range)
Expression exp = this.parser.parse("id == " + Long.MAX_VALUE);
assertThat(exp).isEqualTo(new Expression(EQ, new Key("id"), new Value(Long.MAX_VALUE)));

// id == -9223372036854775808 (Long.MIN_VALUE)
exp = this.parser.parse("id == " + Long.MIN_VALUE);
assertThat(exp).isEqualTo(new Expression(EQ, new Key("id"), new Value(Long.MIN_VALUE)));

// Values within the int range are still parsed as Integer
exp = this.parser.parse("year == 2020");
assertThat(((Value) exp.right()).value()).isInstanceOf(Integer.class).isEqualTo(2020);
}

@Test
public void tesEqAndGte() {
// genre == "drama" AND year >= 2020
Expand Down