Skip to content

Commit 3d39d6e

Browse files
committed
Fix parsing of EQL/JPQL using string literals and enums in IN items.
Closes #3835
1 parent ac4c6e6 commit 3d39d6e

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Eql.g4

+5
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ in_expression
354354

355355
in_item
356356
: literal
357+
| string_expression
358+
| boolean_literal
359+
| numeric_literal
360+
| date_time_timestamp_literal
357361
| single_valued_input_parameter
362+
| conditional_expression
358363
;
359364

360365
like_expression

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4

+5
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ in_expression
338338

339339
in_item
340340
: literal
341+
| string_expression
342+
| boolean_literal
343+
| numeric_literal
344+
| date_time_timestamp_literal
341345
| single_valued_input_parameter
346+
| conditional_expression
342347
;
343348

344349
like_expression

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,23 @@ public List<JpaQueryParsingToken> visitIn_expression(EqlParser.In_expressionCont
12701270
@Override
12711271
public List<JpaQueryParsingToken> visitIn_item(EqlParser.In_itemContext ctx) {
12721272

1273-
List<JpaQueryParsingToken> tokens = new ArrayList<>();
1274-
12751273
if (ctx.literal() != null) {
1276-
tokens.addAll(visit(ctx.literal()));
1274+
return visit(ctx.literal());
1275+
} else if (ctx.string_expression() != null) {
1276+
return visit(ctx.string_expression());
1277+
} else if (ctx.boolean_literal() != null) {
1278+
return visit(ctx.boolean_literal());
1279+
} else if (ctx.numeric_literal() != null) {
1280+
return visit(ctx.numeric_literal());
1281+
} else if (ctx.date_time_timestamp_literal() != null) {
1282+
return visit(ctx.date_time_timestamp_literal());
12771283
} else if (ctx.single_valued_input_parameter() != null) {
1278-
tokens.addAll(visit(ctx.single_valued_input_parameter()));
1284+
return visit(ctx.single_valued_input_parameter());
1285+
} else if (ctx.conditional_expression() != null) {
1286+
return visit(ctx.conditional_expression());
12791287
}
12801288

1281-
return tokens;
1289+
return new ArrayList<>();
12821290
}
12831291

12841292
@Override

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1191,15 +1191,24 @@ public List<JpaQueryParsingToken> visitIn_expression(JpqlParser.In_expressionCon
11911191
@Override
11921192
public List<JpaQueryParsingToken> visitIn_item(JpqlParser.In_itemContext ctx) {
11931193

1194-
List<JpaQueryParsingToken> tokens = new ArrayList<>();
11951194

11961195
if (ctx.literal() != null) {
1197-
tokens.addAll(visit(ctx.literal()));
1196+
return visit(ctx.literal());
1197+
} else if (ctx.string_expression() != null) {
1198+
return visit(ctx.string_expression());
1199+
} else if (ctx.boolean_literal() != null) {
1200+
return visit(ctx.boolean_literal());
1201+
} else if (ctx.numeric_literal() != null) {
1202+
return visit(ctx.numeric_literal());
1203+
} else if (ctx.date_time_timestamp_literal() != null) {
1204+
return visit(ctx.date_time_timestamp_literal());
11981205
} else if (ctx.single_valued_input_parameter() != null) {
1199-
tokens.addAll(visit(ctx.single_valued_input_parameter()));
1206+
return visit(ctx.single_valued_input_parameter());
1207+
} else if (ctx.conditional_expression() != null) {
1208+
return visit(ctx.conditional_expression());
12001209
}
12011210

1202-
return tokens;
1211+
return new ArrayList<>();
12031212
}
12041213

12051214
@Override

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EqlQueryRendererTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,18 @@ WHERE TYPE(e) IN :empTypes
561561
""");
562562
}
563563

564+
@Test
565+
void inClauseWithFunctionAndLiterals() {
566+
567+
assertQuery("""
568+
select f from FooEntity f where upper(f.name) IN ('Y', 'Basic', 'Remit')
569+
""");
570+
assertQuery(
571+
"""
572+
select count(f) from FooEntity f where f.status IN (com.example.eql_bug_check.entity.FooStatus.FOO, com.example.eql_bug_check.entity.FooStatus.BAR)
573+
""");
574+
}
575+
564576
@Test
565577
void notEqualsForTypeShouldWork() {
566578

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,18 @@ WHERE TYPE(e) IN :empTypes
562562
""");
563563
}
564564

565+
@Test
566+
void inClauseWithFunctionAndLiterals() {
567+
568+
assertQuery("""
569+
select f from FooEntity f where upper(f.name) IN ('Y', 'Basic', 'Remit')
570+
""");
571+
assertQuery(
572+
"""
573+
select count(f) from FooEntity f where f.status IN (com.example.eql_bug_check.entity.FooStatus.FOO, com.example.eql_bug_check.entity.FooStatus.BAR)
574+
""");
575+
}
576+
565577
@Test
566578
void notEqualsForTypeShouldWork() {
567579

0 commit comments

Comments
 (0)