Skip to content

Commit ce39069

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 87ed8d5 commit ce39069

File tree

15 files changed

+748
-435
lines changed

15 files changed

+748
-435
lines changed

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

+8-2
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
;
@@ -659,6 +663,7 @@ constructor_name
659663

660664
literal
661665
: STRINGLITERAL
666+
| JAVASTRINGLITERAL
662667
| INTLITERAL
663668
| FLOATLITERAL
664669
| LONGLITERAL
@@ -827,9 +832,9 @@ reserved_word
827832
|OR
828833
|ORDER
829834
|OUTER
835+
|POWER
830836
|REPLACE
831837
|RIGHT
832-
|POWER
833838
|ROUND
834839
|SELECT
835840
|SET
@@ -997,6 +1002,7 @@ NOT_EQUAL : '<>' | '!=' ;
9971002

9981003
CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
9991004
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
1005+
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
10001006
STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
10011007
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
10021008
INTLITERAL : ('0' .. '9')+ ;

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

+20-19
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

@@ -441,6 +433,7 @@ arithmetic_primary
441433
| functions_returning_numerics
442434
| aggregate_expression
443435
| case_expression
436+
| cast_function
444437
| function_invocation
445438
| '(' subquery ')'
446439
;
@@ -453,7 +446,6 @@ string_expression
453446
| aggregate_expression
454447
| case_expression
455448
| function_invocation
456-
| string_expression op='||' string_expression
457449
| '(' subquery ')'
458450
| string_expression '||' string_expression
459451
;
@@ -539,8 +531,8 @@ functions_returning_strings
539531
| SUBSTRING '(' string_expression ',' arithmetic_expression (',' arithmetic_expression)? ')'
540532
| TRIM '(' ((trim_specification)? (trim_character)? FROM)? string_expression ')'
541533
| LOWER '(' string_expression ')'
542-
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
543534
| UPPER '(' string_expression ')'
535+
| REPLACE '(' string_expression ',' string_expression ',' string_expression ')'
544536
| LEFT '(' string_expression ',' arithmetic_expression ')'
545537
| RIGHT '(' string_expression ',' arithmetic_expression ')'
546538
;
@@ -551,6 +543,9 @@ trim_specification
551543
| BOTH
552544
;
553545

546+
cast_function
547+
: CAST '(' single_valued_path_expression (identification_variable)? identification_variable ('(' numeric_literal (',' numeric_literal)* ')')? ')'
548+
;
554549

555550
function_invocation
556551
: FUNCTION '(' function_name (',' function_arg)* ')'
@@ -615,9 +610,6 @@ nullif_expression
615610
: NULLIF '(' scalar_expression ',' scalar_expression ')'
616611
;
617612

618-
cast_expression
619-
: CAST '(' string_expression AS type_literal ')'
620-
;
621613

622614
/*******************
623615
Gaps in the spec.
@@ -631,6 +623,7 @@ trim_character
631623
identification_variable
632624
: IDENTIFICATION_VARIABLE
633625
| f=(COUNT
626+
| AS
634627
| DATE
635628
| FROM
636629
| INNER
@@ -646,6 +639,7 @@ identification_variable
646639
| TIME
647640
| TYPE
648641
| VALUE)
642+
| type_literal
649643
;
650644

651645
constructor_name
@@ -673,6 +667,9 @@ pattern_value
673667

674668
date_time_timestamp_literal
675669
: STRINGLITERAL
670+
| DATELITERAL
671+
| TIMELITERAL
672+
| TIMESTAMPLITERAL
676673
;
677674

678675
entity_type_literal
@@ -965,9 +962,10 @@ ON : O N;
965962
OR : O R;
966963
ORDER : O R D E R;
967964
OUTER : O U T E R;
965+
POWER : P O W E R;
966+
REGEXP : R E G E X P;
968967
REPLACE : R E P L A C E;
969968
RIGHT : R I G H T;
970-
POWER : P O W E R;
971969
ROUND : R O U N D;
972970
SELECT : S E L E C T;
973971
SET : S E T;
@@ -997,8 +995,11 @@ NOT_EQUAL : '<>' | '!=' ;
997995

998996
CHARACTER : '\'' (~ ('\'' | '\\')) '\'' ;
999997
IDENTIFICATION_VARIABLE : ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '$' | '_') ('a' .. 'z' | 'A' .. 'Z' | '\u0080' .. '\ufffe' | '0' .. '9' | '$' | '_')* ;
1000-
STRINGLITERAL : '\'' (~ ('\'' | '\\'))* '\'' ;
998+
STRINGLITERAL : '\'' (~ ('\'' | '\\')|'\\')* '\'' ;
1001999
JAVASTRINGLITERAL : '"' ( ('\\' [btnfr"']) | ~('"'))* '"';
10021000
FLOATLITERAL : ('0' .. '9')* '.' ('0' .. '9')+ (E ('0' .. '9')+)* (F|D)?;
10031001
INTLITERAL : ('0' .. '9')+ ;
1004-
LONGLITERAL : ('0' .. '9')+L ;
1002+
LONGLITERAL : ('0' .. '9')+ L;
1003+
DATELITERAL : '{' D STRINGLITERAL '}';
1004+
TIMELITERAL : '{' T STRINGLITERAL '}';
1005+
TIMESTAMPLITERAL : '{' T S STRINGLITERAL '}';

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

+2-2
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)