HHH-16449 accept underscores in HQL integer and long literals

This commit is contained in:
Gavin 2023-04-09 18:41:58 +02:00 committed by Gavin King
parent 34f05d183a
commit bd57af6d97
3 changed files with 7 additions and 5 deletions

View File

@ -58,9 +58,9 @@ FLOATING_POINT_NUMBER
| DIGIT+
;
INTEGER_LITERAL : INTEGER_NUMBER;
INTEGER_LITERAL : INTEGER_NUMBER ('_' INTEGER_NUMBER)*;
LONG_LITERAL : INTEGER_NUMBER LONG_SUFFIX;
LONG_LITERAL : INTEGER_NUMBER ('_' INTEGER_NUMBER)* LONG_SUFFIX;
FLOAT_LITERAL : FLOATING_POINT_NUMBER FLOAT_SUFFIX?;

View File

@ -3622,7 +3622,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
private SqmLiteral<? extends Number> integerOrLongLiteral(String text) {
try {
final Integer value = Integer.valueOf( text );
final Integer value = Integer.valueOf( text.replace("_", "") );
return new SqmLiteral<>(
value,
resolveExpressibleTypeBasic( Integer.class ),
@ -3651,7 +3651,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
private SqmLiteral<Integer> integerLiteral(String text) {
try {
final Integer value = Integer.valueOf( text );
final Integer value = Integer.valueOf( text.replace("_", "") );
return new SqmLiteral<>(
value,
resolveExpressibleTypeBasic( Integer.class ),
@ -3670,7 +3670,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
final String originalText = text;
try {
if ( text.endsWith( "l" ) || text.endsWith( "L" ) ) {
text = text.substring( 0, text.length() - 1 );
text = text.substring( 0, text.length() - 1 ).replace("_", "");
}
final Long value = Long.valueOf( text );
return new SqmLiteral<>(

View File

@ -302,6 +302,8 @@ public class LiteralTests {
scope.inTransaction(
session -> {
assertThat( session.createQuery( "select 1" ).getSingleResult(), is( 1 ) );
assertThat( session.createQuery( "select 1_000_000" ).getSingleResult(), is( 1_000_000 ) );
assertThat( session.createQuery( "select 1_000_000L" ).getSingleResult(), is( 1_000_000L ) );
}
);
}