File tree 3 files changed +31
-25
lines changed
antlr4/org/springframework/data/jpa/repository/query
java/org/springframework/data/jpa/repository/query
test/java/org/springframework/data/jpa/repository/query
3 files changed +31
-25
lines changed Original file line number Diff line number Diff line change @@ -139,10 +139,6 @@ values
139
139
: ' (' expression (' ,' expression)* ' )'
140
140
;
141
141
142
- projectedItem
143
- : (expression | instantiation) alias?
144
- ;
145
-
146
142
instantiation
147
143
: NEW instantiationTarget ' (' instantiationArguments ' )'
148
144
;
@@ -254,7 +250,7 @@ groupByClause
254
250
;
255
251
256
252
orderByClause
257
- : ORDER BY projectedItem (' ,' projectedItem )*
253
+ : ORDER BY sortedItem (' ,' sortedItem )*
258
254
;
259
255
260
256
havingClause
Original file line number Diff line number Diff line change @@ -457,24 +457,6 @@ public List<JpaQueryParsingToken> visitValues(HqlParser.ValuesContext ctx) {
457
457
return tokens ;
458
458
}
459
459
460
- @ Override
461
- public List <JpaQueryParsingToken > visitProjectedItem (HqlParser .ProjectedItemContext ctx ) {
462
-
463
- List <JpaQueryParsingToken > tokens = new ArrayList <>();
464
-
465
- if (ctx .expression () != null ) {
466
- tokens .addAll (visit (ctx .expression ()));
467
- } else if (ctx .instantiation () != null ) {
468
- tokens .addAll (visit (ctx .instantiation ()));
469
- }
470
-
471
- if (ctx .alias () != null ) {
472
- tokens .addAll (visit (ctx .alias ()));
473
- }
474
-
475
- return tokens ;
476
- }
477
-
478
460
@ Override
479
461
public List <JpaQueryParsingToken > visitInstantiation (HqlParser .InstantiationContext ctx ) {
480
462
@@ -858,8 +840,8 @@ public List<JpaQueryParsingToken> visitOrderByClause(HqlParser.OrderByClauseCont
858
840
tokens .add (new JpaQueryParsingToken (ctx .ORDER ()));
859
841
tokens .add (new JpaQueryParsingToken (ctx .BY ()));
860
842
861
- ctx .projectedItem ().forEach (projectedItemContext -> {
862
- tokens .addAll (visit (projectedItemContext ));
843
+ ctx .sortedItem ().forEach (sortedItemContext -> {
844
+ tokens .addAll (visit (sortedItemContext ));
863
845
NOSPACE (tokens );
864
846
tokens .add (TOKEN_COMMA );
865
847
});
Original file line number Diff line number Diff line change @@ -1430,4 +1430,32 @@ void hqlQueries() {
1430
1430
"order by p " + //
1431
1431
"limit 50" );
1432
1432
}
1433
+
1434
+ @ Test // GH-2962
1435
+ void orderByWithNullsFirstOrLastShouldWork () {
1436
+
1437
+ assertThatNoException ().isThrownBy (() -> {
1438
+ parseWithoutChanges ("""
1439
+ select a,
1440
+ case
1441
+ when a.geaendertAm is null then a.erstelltAm
1442
+ else a.geaendertAm end as mutationAm
1443
+ from Element a
1444
+ where a.erstelltDurch = :variable
1445
+ order by mutationAm desc nulls first
1446
+ """ );
1447
+ });
1448
+
1449
+ assertThatNoException ().isThrownBy (() -> {
1450
+ parseWithoutChanges ("""
1451
+ select a,
1452
+ case
1453
+ when a.geaendertAm is null then a.erstelltAm
1454
+ else a.geaendertAm end as mutationAm
1455
+ from Element a
1456
+ where a.erstelltDurch = :variable
1457
+ order by mutationAm desc nulls last
1458
+ """ );
1459
+ });
1460
+ }
1433
1461
}
You can’t perform that action at this time.
0 commit comments