From 1c7a19a054326a67b17eee2d44770b27ee3706a8 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Mon, 22 May 2023 15:20:10 -0500 Subject: [PATCH] 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 --- .../data/jpa/repository/query/Hql.g4 | 1 - .../query/HqlQueryRendererTests.java | 27 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 index 80af871fc..8796cf1f8 100644 --- a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 +++ b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 @@ -977,7 +977,6 @@ RANGE : R A N G E; RESPECT : R E S P E C T; RIGHT : R I G H T; ROLLUP : R O L L U P; -ROUND : R O U N D; ROW : R O W; ROWS : R O W S; SEARCH : S E A R C H; diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryRendererTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryRendererTests.java index 672c65aba..f6343f51b 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryRendererTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryRendererTests.java @@ -1448,13 +1448,26 @@ class HqlQueryRendererTests { assertThatNoException().isThrownBy(() -> { parseWithoutChanges(""" - select a, - case - when a.geaendertAm is null then a.erstelltAm - else a.geaendertAm end as mutationAm - from Element a - where a.erstelltDurch = :variable - order by mutationAm desc nulls last + select a, + case + when a.geaendertAm is null then a.erstelltAm + else a.geaendertAm end as mutationAm + from Element a + where a.erstelltDurch = :variable + order by mutationAm desc nulls last + """); + }); + } + + @Test // GH-2964 + void roundFunctionShouldWorkLikeAnyOtherFunction() { + + assertThatNoException().isThrownBy(() -> { + parseWithoutChanges(""" + select round(count(ri) * 100 / max(ri.receipt.positions), 0) as perc + from StockOrderItem oi + right join StockReceiptItem ri + on ri.article = oi.article """); }); }