Skip to content

Commit 3effe55

Browse files
committed
Polishing.
Inline select_query into select_statement, simplify set_function resolution. Align JPQL and EQL grammars. Adopt Hibernate version guards in tests. Original Pull Request: #3695
1 parent 2b56242 commit 3effe55

File tree

15 files changed

+712
-425
lines changed

15 files changed

+712
-425
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ql_statement
4343
;
4444

4545
select_statement
46-
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (setOperator select_statement)*
46+
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (set_fuction)?
4747
;
4848

4949
setOperator
@@ -52,6 +52,10 @@ setOperator
5252
| EXCEPT ALL?
5353
;
5454

55+
set_fuction
56+
: setOperator select_statement
57+
;
58+
5559
update_statement
5660
: update_clause (where_clause)?
5761
;
@@ -675,6 +679,7 @@ constructor_name
675679

676680
literal
677681
: STRINGLITERAL
682+
| JAVASTRINGLITERAL
678683
| INTLITERAL
679684
| FLOATLITERAL
680685
| LONGLITERAL
@@ -848,9 +853,9 @@ reserved_word
848853
|OR
849854
|ORDER
850855
|OUTER
856+
|POWER
851857
|REPLACE
852858
|RIGHT
853-
|POWER
854859
|ROUND
855860
|SELECT
856861
|SET
@@ -1021,6 +1026,7 @@ NOT_EQUAL : '<>' | '!=' ;
10211026

10221027
CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
10231028
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
1029+
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
10241030
STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
10251031
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
10261032
INTLITERAL : ('0' .. '9')+ ;

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ ql_statement
4343
;
4444

4545
select_statement
46-
: select_query
47-
;
48-
49-
select_query
5046
: select_clause from_clause (where_clause)? (groupby_clause)? (having_clause)? (orderby_clause)? (set_fuction)?
5147
;
5248

@@ -57,11 +53,7 @@ setOperator
5753
;
5854

5955
set_fuction
60-
: setOperator set_function_select
61-
;
62-
63-
set_function_select
64-
: select_query
56+
: setOperator select_statement
6557
;
6658

6759
update_statement
@@ -95,7 +87,7 @@ join
9587
;
9688

9789
fetch_join
98-
: join_spec FETCH join_association_path_expression
90+
: join_spec FETCH join_association_path_expression AS? identification_variable? join_condition?
9991
;
10092

10193
join_spec
@@ -315,7 +307,7 @@ scalar_expression
315307
| datetime_expression
316308
| boolean_expression
317309
| case_expression
318-
| cast_expression
310+
| cast_function
319311
| entity_type_expression
320312
;
321313

@@ -550,8 +542,8 @@ functions_returning_strings
550542
| SUBSTRING '(' string_expression ',' arithmetic_expression (',' arithmetic_expression)? ')'
551543
| TRIM '(' ((trim_specification)? (trim_character)? FROM)? string_expression ')'
552544
| LOWER '(' string_expression ')'
553-
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
554545
| UPPER '(' string_expression ')'
546+
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
555547
| LEFT '(' string_expression ',' arithmetic_expression ')'
556548
| RIGHT '(' string_expression ',' arithmetic_expression ')'
557549
;
@@ -637,9 +629,6 @@ nullif_expression
637629
: NULLIF '(' scalar_expression ',' scalar_expression ')'
638630
;
639631

640-
cast_expression
641-
: CAST '(' string_expression AS type_literal ')'
642-
;
643632

644633
/*******************
645634
Gaps in the spec.
@@ -653,6 +642,7 @@ trim_character
653642
identification_variable
654643
: IDENTIFICATION_VARIABLE
655644
| f=(COUNT
645+
| AS
656646
| DATE
657647
| FROM
658648
| INNER
@@ -668,6 +658,7 @@ identification_variable
668658
| TIME
669659
| TYPE
670660
| VALUE)
661+
| type_literal
671662
;
672663

673664
constructor_name
@@ -695,6 +686,9 @@ pattern_value
695686

696687
date_time_timestamp_literal
697688
: STRINGLITERAL
689+
| DATELITERAL
690+
| TIMELITERAL
691+
| TIMESTAMPLITERAL
698692
;
699693

700694
entity_type_literal
@@ -995,10 +989,10 @@ ON : O N;
995989
OR : O R;
996990
ORDER : O R D E R;
997991
OUTER : O U T E R;
998-
REPLACE : R E P L A C E;
999-
RIGHT : R I G H T;
1000992
POWER : P O W E R;
1001993
REGEXP : R E G E X P;
994+
REPLACE : R E P L A C E;
995+
RIGHT : R I G H T;
1002996
ROUND : R O U N D;
1003997
SELECT : S E L E C T;
1004998
SET : S E T;
@@ -1033,4 +1027,7 @@ STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
10331027
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
10341028
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
10351029
INTLITERAL : ('0' .. '9')+ ;
1036-
LONGLITERAL : ('0' .. '9')+L ;
1030+
LONGLITERAL : ('0' .. '9')+ L;
1031+
DATELITERAL : '{' D STRINGLITERAL '}';
1032+
TIMELITERAL : '{' T STRINGLITERAL '}';
1033+
TIMESTAMPLITERAL : '{' T S STRINGLITERAL '}';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EqlCountQueryTransformer extends EqlQueryRenderer {
4242
}
4343

4444
@Override
45-
public QueryRendererBuilder visitSelect_statement(EqlParser.Select_statementContext ctx) {
45+
public QueryTokenStream visitSelect_statement(EqlParser.Select_statementContext ctx) {
4646

4747
QueryRendererBuilder builder = QueryRenderer.builder();
4848

@@ -92,7 +92,7 @@ public QueryTokenStream visitSelect_clause(EqlParser.Select_clauseContext ctx) {
9292
return builder;
9393
}
9494

95-
private QueryRendererBuilder getDistinctCountSelection(QueryTokenStream selectionListbuilder) {
95+
private QueryTokenStream getDistinctCountSelection(QueryTokenStream selectionListbuilder) {
9696

9797
QueryRendererBuilder nested = new QueryRendererBuilder();
9898
CountSelectionTokenStream countSelection = CountSelectionTokenStream.create(selectionListbuilder);

0 commit comments

Comments
 (0)