Skip to content

Commit 6d20cab

Browse files
committed
ROUND doesn't need to be a reserved word.
Because ROUND is a reserved word yet is NOT on the list of approved functions, it fails to get parsed. Simply dropping it from the list of reserved words makes it succeed in the HQL query parser. See #2964 Original Pull Request: #2966
1 parent 1ac50e4 commit 6d20cab

File tree

2 files changed

+20
-8
lines changed
  • spring-data-jpa/src

2 files changed

+20
-8
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ RANGE : R A N G E;
977977
RESPECT : R E S P E C T;
978978
RIGHT : R I G H T;
979979
ROLLUP : R O L L U P;
980-
ROUND : R O U N D;
981980
ROW : R O W;
982981
ROWS : R O W S;
983982
SEARCH : S E A R C H;

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

+20-7
Original file line numberDiff line numberDiff line change
@@ -1448,13 +1448,26 @@ void orderByWithNullsFirstOrLastShouldWork() {
14481448

14491449
assertThatNoException().isThrownBy(() -> {
14501450
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
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+
}
1461+
1462+
@Test // GH-2964
1463+
void roundFunctionShouldWorkLikeAnyOtherFunction() {
1464+
1465+
assertThatNoException().isThrownBy(() -> {
1466+
parseWithoutChanges("""
1467+
select round(count(ri) * 100 / max(ri.receipt.positions), 0) as perc
1468+
from StockOrderItem oi
1469+
right join StockReceiptItem ri
1470+
on ri.article = oi.article
14581471
""");
14591472
});
14601473
}

0 commit comments

Comments
 (0)