Skip to content

Commit 18db5fa

Browse files
committed
Refine HQL rendering of CTE with SEARCH clause.
Add tests for CYCLE, ensure no space between search order items. Closes #4012
1 parent bc234f0 commit 18db5fa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public QueryTokenStream visitCteAttributes(HqlParser.CteAttributesContext ctx) {
131131
return QueryTokenStream.concat(ctx.identifier(), this::visit, TOKEN_COMMA);
132132
}
133133

134+
@Override
135+
public QueryTokenStream visitSearchSpecifications(HqlParser.SearchSpecificationsContext ctx) {
136+
return QueryTokenStream.concat(ctx.searchSpecification(), this::visit, TOKEN_COMMA);
137+
}
138+
134139
@Override
135140
public QueryTokenStream visitOrderedQuery(HqlParser.OrderedQueryContext ctx) {
136141

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,31 @@ WITH maxId AS (select max(sr.snapshot.id) snapshotId from SnapshotReference sr
20972097
""");
20982098
}
20992099

2100+
@Test // GH-4012
2101+
void cteWithSearch() {
2102+
2103+
assertQuery("""
2104+
WITH Tree AS (SELECT o.uuid AS test_uuid FROM DemoEntity o)
2105+
SEARCH BREADTH FIRST BY foo ASC NULLS FIRST, bar DESC NULLS LAST SET baz
2106+
SELECT test_uuid FROM Tree
2107+
""");
2108+
}
2109+
2110+
@Test // GH-4012
2111+
void cteWithCycle() {
2112+
2113+
assertQuery("""
2114+
WITH Tree AS (SELECT o.uuid AS test_uuid FROM DemoEntity o) CYCLE test_uuid SET circular TO true DEFAULT false
2115+
SELECT test_uuid FROM Tree
2116+
""");
2117+
2118+
assertQuery(
2119+
"""
2120+
WITH Tree AS (SELECT o.uuid AS test_uuid FROM DemoEntity o) CYCLE test_uuid SET circular TO true DEFAULT false USING bar
2121+
SELECT test_uuid FROM Tree
2122+
""");
2123+
}
2124+
21002125
@Test // GH-2982
21012126
void floorShouldBeValidEntityName() {
21022127

0 commit comments

Comments
 (0)